#include<bits/stdc++.h>
#define fo(i,d,c) for(int i=d;i<=c;i++)
#define fod(i,c,d) for(int i=c;i>=d;i--)
#define maxn 1000010
#define N 1010
#define fi first
#define se second
#define pb emplace_back
#define en cout<<"\n";
#define int long long
#define inf (int)1e18
#define pii pair<int,int>
#define vii vector<pii>
#define lb(x) x&-x
#define bit(i,j) ((i>>j)&1)
#define offbit(i,j) (i^(1<<j))
#define onbit(i,j) (i|(1<<j))
#define vi vector<int>
template <typename T1, typename T2> bool minimize(T1 &a, T2 b){if (a > b) {a = b; return true;} return false;}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b){if (a < b) {a = b; return true;} return false;}
using namespace std;
const int nsqrt = 450;
const int mod = 1e9 + 7;
struct node
{
int val,lazy;
node *l,*r;
node()
{
val = lazy = 0;
l = r = 0;
}
};
node *root = new node();
void down(node *id,int l,int r)
{
if(id -> lazy == 0) return;
int mid = (l + r) >> 1;
id -> l -> val += (mid - l + 1) * id -> lazy;
id -> r -> val += (r - mid) * id -> lazy;
id -> l -> lazy += id -> lazy;
id -> r -> lazy += id -> lazy;
id -> lazy = 0;
}
void up(node *id,int l,int r,int u,int v,int val)
{
if(l > v or r < u) return;
if(u <= l and r <= v)
{
id -> val += (r - l + 1) * val;
id -> lazy += val;
return;
}
if(id -> l == NULL) id -> l = new node();
if(id -> r == NULL) id -> r = new node();
int mid = (l + r) >> 1;
down(id,l,r);
up(id -> l,l,mid,u,v,val);
up(id -> r,mid + 1,r,u,v,val);
id -> val = id -> l -> val + id -> r -> val;
}
int get(node *id,int l,int r,int u,int v)
{
if(l > v or r < u) return 0;
if(u <= l and r <= v) return id -> val;
int mid = (l + r) >> 1;
if(id -> l == NULL) id -> l = new node();
if(id -> r == NULL) id -> r = new node();
down(id,l,r);
return get(id -> l,l,mid,u,v) + get(id -> r,mid + 1,r,u,v);
}
int q;
int t,l,r;
int c;
main()
{
#define name "TASK"
if(fopen(name".inp","r"))
{
freopen(name".inp","r",stdin);
freopen(name".out","w",stdout);
}
ios_base::sync_with_stdio(false);cin.tie(NULL);
cin >> q;
while(q--)
{
cin >> t >> l >> r;
if(t == 1)
{
c = get(root,1,1e9,l + c,r + c);
cout << c;en;
}
else up(root,1,1e9,l + c,r + c,1);
}
}
Compilation message
apple.cpp:75:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
75 | main()
| ^~~~
apple.cpp: In function 'int main()':
apple.cpp:80:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
80 | freopen(name".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
apple.cpp:81:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
81 | freopen(name".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |