HDU 4893
Wow! Such Sequence!
Wow! Such Sequence!
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 2407 Accepted Submission(s): 711
Problem Description
Recently, Doge got a funny birthday present from his new friend, Protein Tiger from St. Beeze College. No, not cactuses. It’s a mysterious blackbox.After some research, Doge found that the box is maintaining a sequence an of n numbers internally, initially all numbers are zero, and there are THREE “operations”: 1.Add d to the k-th number of the sequence. 2.Query the sum of ai where l ≤ i ≤ r. 3.Change ai to the nearest Fibonacci number, where l ≤ i ≤ r. 4.Play sound “Chee-rio!”, a bit useless. Let F0 = 1,F1 = 1,Fibonacci number Fn is defined as Fn = Fn - 1 + Fn - 2 for n ≥ 2. Nearest Fibonacci number of number x means the smallest Fn where |Fn - x| is also smallest. Doge doesn’t believe the machine could respond each request in less than 10ms. Help Doge figure out the reason.
Input
Input contains several test cases, please process till EOF. For each test case, there will be one line containing two integers n, m. Next m lines, each line indicates a query:1 k d - “add” 2 l r - “query sum” 3 l r - “change to nearest Fibonacci” 1 ≤ n ≤ 100000, 1 ≤ m ≤ 100000, |d| < 231, all queries will be valid.
Output
For each Type 2 (“query sum”) operation, output one line containing an integer represent the answer of this query.
Sample Input
1 1 2 1 1 5 4 1 1 7 1 3 17 3 2 4 2 1 5
Sample Output
0 22
Author
Fudan University
Source
2014 Multi-University Training Contest 3
水题。 理解题意就可以了, int WA了,改成long long AC
/* ***
Author :kuangbin
Created Time :2014/8/3 16:39:04
File Name :E:\2014ACM\比赛\2014多校训练\2014多校3\HDU4891.cpp
************************************************ */
#include <stdio.h>
#include <string.h>
#include
#include
#include
#include
#include
#include
#include
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
char str[1010][10100];
int main()
{
//freopen(“in.txt”,”r”,stdin);
//freopen(“out.txt”,”w”,stdout);
int n;
while(scanf(“%d”,&n) == 1)
{
gets(str[0]);
for(int i = 0;i < n;i++)
gets(str[i]);
long long ans = 1;
int c0 = 0, c1 = 0;
int cnt0 = 0, cnt1 = 0;
for(int i = 0;i < n;i++)
{
if(ans > 100000)break;
int len = strlen(str[i]);
for(int j = 0;j < len;j++)
{
if(str[i][j] == ‘$’)
{
if(c0 == 0)c0 = 1;
else
{
ans = (cnt0+1);
cnt0 = 0;
c0 = 0;
}
}
if(str[i][j] == ‘{‘)
c1 = 1;
if(str[i][j] == ‘}’)
{
c1 = 0;
ans = (cnt1+1);
cnt1 = 0;
}
if(c0 > 0)
{
if(str[i][j] == ‘ ‘)
cnt0++;
else
{
ans *= (cnt0+1);
cnt0 = 0;
}
}
if(c1 > 0 && str[i][j] == ‘|’)
cnt1++;
if(ans > 100000)break;
}
}
if(ans > 100000)printf(“doge\n”);
else printf(“%d\n”,(int)ans);
}
return 0;
}