Submission #1129158

#TimeUsernameProblemLanguageResultExecution timeMemory
1129158FanOfWilliamLinMonkey and Apple-trees (IZhO12_apple)C++20
0 / 100
2 ms320 KiB
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template <class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; //- insert(x),erase(x) //- find_by_order(k): return iterator to the k-th smallest element //- order_of_key(x): the number of elements that are strictly smaller #define ll long long #define ld long double #define ar array #define vt vector #define pb push_back #define bit(i, x) ((x>>i)&1ULL) #define pf push_front #define all(v) v.begin(), v.end() #define lla(v) v.rbegin(), v.rend() #define pii pair<int, int> #define x first #define y second /*mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); ll get_rand(ll l, ll r) { return uniform_int_distribution<ll> (l, r)(rng); }*/ struct SparseSegtree { struct Node { int freq=0; int lazy=0; int left=-1; int right=-1; }; vector<Node> st; int n, q, timer=1; void init(int _n, int _q=0) { n=_n; q=_q; if(q>0) { st.reserve(2*q*__lg(n)); } st.pb(Node()); st.pb(Node()); } int combine(int a, int b) { return a+b; } void apply(int id, int len, int val) { if(val==1) { st[id].lazy=val; st[id].freq=len*val; } } void psh(int id, int l, int r) { if(st[id].left==-1) { st[id].left=++timer; st.push_back(Node()); } if(st[id].right==-1) { st[id].right=++timer; st.push_back(Node()); } int mid=(l+r)/2; apply(st[id].left, mid-l+1, st[id].lazy); apply(st[id].right, r-mid, st[id].lazy); st[id].lazy=0; } void range_set(int id, int l, int r, int u, int v, int val) { if(v<l||u>r) { return; } if(u<=l&&r<=v) { apply(id, r-l+1, val); return; } psh(id, l, r); int mid=(l+r)/2; range_set(st[id].left, l, mid, u, v, val); range_set(st[id].right, mid+1, r, u, v, val); st[id].freq=combine(st[st[id].left].freq, st[st[id].right].freq); } int range_sum(int id, int l, int r, int u, int v) { if(v<l||u>r) { return 0; } if(u<=l&&r<=v) { return st[id].freq; } psh(id, l, r); int mid=(l+r)/2; return combine(range_sum(st[id].left, l, mid, u, v), range_sum(st[id].right, mid+1, r, u, v)); } void range_set(int ql, int qr, int val) { range_set(1, 1, n, ql, qr, val); } int range_sum(int ql, int qr) { return range_sum(1, 1, n, ql, qr); } } st; void solve() { int query_num; cin >> query_num; const int RANGE_SIZE = 1e9; st.init(RANGE_SIZE+1, query_num); int c = 0; for (int i = 0; i < query_num; i++) { int type, x, y; cin >> type >> x >> y; if (type == 1) { c = st.range_sum(x+c, y+c); cout << c << '\n'; } else if (type == 2) { st.range_set(x+c, y+c, 1); } } } signed main() { ios::sync_with_stdio(0); cin.tie(0); freopen("f.in", "r", stdin); freopen("f.out", "w", stdout); int TC=1; //cin >> TC; while(TC--) { solve(); } }

Compilation message (stderr)

apple.cpp: In function 'int main()':
apple.cpp:125:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  125 |         freopen("f.in", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~
apple.cpp:126:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  126 |   freopen("f.out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...