Submission #1211929

#TimeUsernameProblemLanguageResultExecution timeMemory
1211929RafatMonkey and Apple-trees (IZhO12_apple)C++20
100 / 100
243 ms137388 KiB
#include <bits/stdc++.h> #include <time.h> #include <cstdlib> #include <ctime> #include <cstdio> #include <cstring> #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <iostream> using namespace __gnu_pbds; using namespace std; template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // to erase in multiset-> less_equal<T> and // s.erase(s.find_by_order(s.order_of_key(x))) // lower_bound(x)=>(cannot use the stl lower_bound function) // ll idx = s.order_of_key(x) // if(idx == s.size()) -> no lower_bound // else lb = *s.find_by_order(idx) // as 0-indexing // idx-1 will give highest value which is strictly less than x // for upper_bound->do the same with (x+1) typedef long long ll; typedef long double ld; typedef pair<int,int> p32; typedef pair<ll,ll> p64; typedef tuple<ll, ll, ll> t64; typedef vector<t64> vt64; typedef vector<vt64> vvt64; typedef pair<double,double> pdd; typedef vector<ll> v64; typedef vector<int> v32; typedef vector<vector<int> > vv32; typedef vector<vector<ll> > vv64; typedef vector<vector<p64> > vvp64; typedef vector<p64> vp64; typedef vector<p32> vp32; typedef vector<vector<p32> > vvp32; typedef vector<bool> vb; ll mod = 1e9+7, MOD = 998244353; double eps = 1e-12; #define FOR(s, e, i) for(ll i = s; i <= e; i++) #define ROF(s ,e, i) for(ll i = s; i >= e; i--) #define F0R(i, e) for(ll i = 0; i < (e); i++) #define trav(e, a) for(auto &e : a) #define coutAll(A) for(auto asdafas : A) cout << asdafas << " "; cout << "\n"; #define foutAll(A) for(auto asdafas : A) fout << asdafas << " "; cout << "\n"; #define cinAll(A) for(auto &asdafas : A) cin >> asdafas; #define finAll(A) for(auto &asdafas : A) fin >> asdafas; #define minpq priority_queue<ll, v64, greater<ll>> #define maxpq priority_queue<ll> #define ln "\n" #define dbg(x) cout<<#x<<" = "<<x<<ln #define mp make_pair #define mt make_tuple #define pb push_back #define fi first #define se second ll inf = LLONG_MAX; #define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) ((ll)(x).size()) #define yes cout<<"yes\n" #define no cout<<"no\n" #define Yes cout<<"Yes\n" #define No cout<<"No\n" #define YES cout<<"YES\n" #define NO cout<<"NO\n" using namespace std; typedef long long ll; typedef vector<ll> vll; typedef vector<vector<ll>> vvll; typedef pair<ll, ll> pll; typedef pair<ll, ll> pii; #define MAXN 100000000 class SparseSegtree { private: struct Node { int freq = 0; int lazy = 0; Node *left = nullptr; Node *right = nullptr; }; Node *root = new Node; const int n; int comb(int a, int b) { return a + b; } void apply(Node *cur, int len, int val) { if (val == 1) { (cur->lazy) = val; (cur->freq) = len * val; } } void push_down(Node *cur, int l, int r) { if ((cur->left) == nullptr) { (cur->left) = new Node; } if ((cur->right) == nullptr) { (cur->right) = new Node; } int m = (l + r) / 2; apply(cur->left, m - l + 1, cur->lazy); apply(cur->right, r - m, cur->lazy); } void range_set(Node *cur, int l, int r, int ql, int qr, int val) { if (qr < l || ql > r) { return; } if (ql <= l && r <= qr) { apply(cur, r - l + 1, val); } else { push_down(cur, l, r); int m = (l + r) / 2; range_set(cur->left, l, m, ql, qr, val); range_set(cur->right, m + 1, r, ql, qr, val); (cur->freq) = comb((cur->left)->freq, (cur->right)->freq); } } int range_sum(Node *cur, int l, int r, int ql, int qr) { if (qr < l || ql > r) { return 0; } if (ql <= l && r <= qr) { return cur->freq; } push_down(cur, l, r); int m = (l + r) / 2; return comb(range_sum(cur->left, l, m, ql, qr), range_sum(cur->right, m + 1, r, ql, qr)); } public: SparseSegtree(int n) : n(n) {} void range_set(int ql, int qr, int val) { range_set(root, 0, n - 1, ql, qr, val); } int range_sum(int ql, int qr) { return range_sum(root, 0, n - 1, ql, qr); } }; void solve(int it) { int q; cin >> q; SparseSegtree st(1000000005); int ans = 0; while(q--){ int c, l, r; cin >> c >> l >> r; if(c==1){ ans = st.range_sum(l+ans, r+ans); cout << ans << "\n"; }else{ st.range_set(l+ans, r+ans, 1); } } } int main() { fast_cin(); ll t = 1; // cin >> t; for(int it=1; it<=t; it++) { //cout << "Case " << it << ": "; solve(it); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...