#include<bits/stdc++.h>
using namespace std;
#define int long long
int N = 1<<30;
map<int, int> bit;
void update(int curr, int l, int r, int cl, int cr)
{
if (cr < l || cl > r) return;
if (l <= cl && cr <= r)
{
bit[curr] = cr-cl+1;
return;
}
if(bit[curr] == cr-cl+1)
{
bit[curr*2] = (cr-cl+1)/2;
bit[curr*2+1]=(cr-cl+1)/2;
}
int m = (cl+cr)/2;
update(curr*2, l, r, cl, m);
update(curr*2+1, l, r, m+1, cr);
bit[curr] = bit[curr*2]+bit[curr*2+1];
return;
}
int query(int curr, int l, int r, int cl, int cr)
{
if (cr < l || cl > r) return 0;
if (l <= cl && cr <= r) return bit[curr];
if(bit[curr] == cr-cl+1)
{
bit[curr*2] = (cr-cl+1)/2;
bit[curr*2+1]=(cr-cl+1)/2;
}
int m = (cl+cr)/2;
int sol = 0;
sol += query(curr*2, l, r, cl, m);
sol += query(curr*2+1, l, r, m+1, cr);
return sol;
}
int32_t main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int q;
cin >> q;
int last = 0;
for (int i = 0; i < q; i++)
{
int a, b, c;
cin >> a >> b >> c;
b--; c--;
b+=last;
c+=last;
if (a==2)
{
update(1, b, c, 0, N-1);
}
else
{
last = query(1, b, c, 0, N-1);
cout << last << "\n";
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
98 ms |
6228 KB |
Output is correct |
5 |
Correct |
128 ms |
7644 KB |
Output is correct |
6 |
Correct |
125 ms |
7248 KB |
Output is correct |
7 |
Correct |
126 ms |
7464 KB |
Output is correct |
8 |
Correct |
1260 ms |
56856 KB |
Output is correct |
9 |
Execution timed out |
2061 ms |
89036 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |