#include <bits/stdc++.h>
using namespace std;
#define ll long long
//#define ld long double
#define all(x) x.begin(), x.end()
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <class T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define file \
freopen("haybales.in", "r", stdin);\
freopen("haybales.out", "w", stdout)
#define OJudge(in,out) \
freopen(in, "r", stdin);\
freopen(out, "w", stdout)
#define FIn \
cin.tie(0); \
cout.tie(0); \
ios_base::sync_with_stdio(false)
const string IN = "input.txt";
const string OUT = "output.txt";
int tc;
ll n, m, a, b, c,d, k;
struct no{
int sum = 0, lazy = 0;
no* left = nullptr;
no* right = nullptr;
};
class dyn_segtree{
no* root = new no;
int size;
public:
dyn_segtree(int n){
size = n;
}
void push(int l, int r, no* node){
int mid = (l + r)/2;
if(r - l){
if (!node->left) {
no *l1 = new no;
node->left = l1;
}
if (!node->right) {
no *r1 = new no;
node->right = r1;
}
node->left->lazy |= node->lazy;
node->right->lazy |= node->lazy;
}
if(node->lazy)
node->sum = (r - l + 1)*node->lazy;
node->lazy = 0;
}
void set(int l1, int r1, int l, int r, no* node){
push(l , r, node);
if(r < l1 || l > r1)
return;
if(l >= l1 && r <= r1){
node->lazy = 1;
push(l , r, node);
return;
}
int mid = (l + r)/2;
set(l1 , r1, l , mid, node->left);
set(l1 , r1, mid + 1, r, node->right);
node->sum = node->left->sum + node->right->sum;
}
void set(int l, int r){
set(l , r, 1 , size , root);
}
ll get(int l1, int r1, int l, int r, no* node){
push(l , r, node);
if(!node->sum || r < l1 || l > r1)
return 0;
if(l >= l1 && r <= r1)
return node->sum;
int mid = (l + r)/2;
auto s1 = get(l1, r1, l, mid, node->left);
auto s2 = get(l1, r1, mid + 1, r, node->right);
return s1 + s2;
}
ll get(int l, int r){
return get(l , r, 1 , size , root);
}
};
void solve(){
cin>>n;
dyn_segtree sg(1000000000);
c = 0;
for(int i = 0; i < n; i++){
cin>>a;
if(a == 1){
cin>>a>>b;
c = sg.get(a + c, b + c);
cout<<c<<"\n";
}else{
cin>>a>>b;
sg.set(a + c, b + c);
}
}
}
int main() {
FIn;
// file;
#ifndef ONLINE_JUDGE
OJudge(IN.c_str(),OUT.c_str());
#endif
bool test = 0;
if (test)
cin>>tc;
else tc = 1;
for (int i = 1; i<=tc; i++){
solve();
}
}
컴파일 시 표준 에러 (stderr) 메시지
apple.cpp: In function 'int main()':
apple.cpp:18:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
18 | freopen(in, "r", stdin);\
| ~~~~~~~^~~~~~~~~~~~~~~~
apple.cpp:126:5: note: in expansion of macro 'OJudge'
126 | OJudge(IN.c_str(),OUT.c_str());
| ^~~~~~
apple.cpp:19:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
19 | freopen(out, "w", stdout)
| ~~~~~~~^~~~~~~~~~~~~~~~~~
apple.cpp:126:5: note: in expansion of macro 'OJudge'
126 | OJudge(IN.c_str(),OUT.c_str());
| ^~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |