#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mxN = 1e9+100;
struct SegTree {
struct Node {
ll val = 0, lazy = 0;
Node* left = NULL;
Node* right = NULL;
};
typedef Node* root;
root R = NULL;
SegTree(int n) {
R = new Node();
}
void push(root nd, ll l, ll r) {
if (nd == NULL || nd->lazy == 0) return;
nd->val = (r - l + 1) * nd->lazy;
if (r - l > 0) {
if (nd->left == NULL) nd->left = new Node;
if (nd->right == NULL) nd->right = new Node;
nd->left->lazy = nd->lazy;
nd->right->lazy = nd->lazy;
}
nd->lazy = 0;
}
void update(root nd, ll start, ll end, ll l, ll r) {
if (nd == NULL) return;
push(nd, start, end);
if (start > r || end < l) return;
if (start >= l && end <= r) {
nd->lazy = 1;
push(nd, start, end);
return;
}
ll mid = start + (end - start) / 2;
if (nd->left == NULL) nd->left = new Node;
if (nd->right == NULL) nd->right = new Node;
update(nd->left, start, mid, l, r);
update(nd->right, mid + 1, end, l, r);
nd->val = (nd->left ? nd->left->val : 0) + (nd->right ? nd->right->val : 0);
}
ll qry(root nd, ll start, ll end, ll l, ll r) {
if (nd == NULL) return 0;
push(nd, start, end);
if (start > r || end < l) return 0;
if (start >= l && end <= r) return nd->val;
ll mid = start + (end - start) / 2;
return qry(nd->left, start, mid, l, r) + qry(nd->right, mid + 1, end, l, r);
}
void update(ll l, ll r) {
update(this->R, 1, mxN, l, r);
}
ll qry(ll l, ll r) {
return qry(this->R, 1, mxN, l, r);
}
};
int main() {
#ifndef ONLINE_JUDGE
freopen("input.in","r",stdin);
freopen("output.out","w",stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
ll n,prev=0,e,l,r;cin>>n;
SegTree seg_tree(mxN);
while(n--){
cin>>e>>l>>r;
l+=prev;
r+=prev;
if(e==1){
prev=seg_tree.qry(l,r);
cout<<prev<<'\n';
}else if(e==2){
seg_tree.update(l,r);
}
}
return 0;
}
Compilation message
apple.cpp: In function 'int main()':
apple.cpp:73:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
73 | freopen("input.in","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
apple.cpp:74:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
74 | freopen("output.out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2027 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |