# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1001034 | LilPluton | Monkey and Apple-trees (IZhO12_apple) | C++14 | 393 ms | 262144 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
/// author: LilPluton auuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
#define OPT ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int ll
#define ll long long
#define pb push_back
#define arr array
#define vll vector<int>
#define segment_tree int l=n*2,r=l+1,mid=(b+e)/2
#define fi first
#define se second
#define rep(i,j,k) for(int i = j; i <= k; ++i)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define endll '\n'
using namespace std;
const int sz = (6e6 + 100);
const int N = 1e9;
int t[sz * 4], L[sz * 4], R[sz * 4], nxt = 1, lz[sz * 4];
void init(int node,int l,int r)
{
if(lz[node])
{
t[node] = r - l + 1;
if(l != r){
if(!L[node]) L[node] = ++nxt;
if(!R[node]) R[node] = ++nxt;
lz[L[node]] = 1;
lz[R[node]] = 1;
}
lz[node] = 0;
}
}
void upd(int node,int l,int r,int ql,int qr)
{
init(node,l,r);
if(ql > r || qr < l)
return;
if(ql <= l && r <= qr)
{
t[node] = r - l + 1;
if(l != r){
if(!L[node]) L[node] = ++nxt;
if(!R[node]) R[node] = ++nxt;
lz[L[node]] = 1;
lz[R[node]] = 1;
}
return;
}
ll mid = (l + r) >> 1;
if(!L[node]) L[node]= ++nxt;
upd(L[node], l, mid, ql, qr);
if(!R[node]) R[node] = ++nxt;
upd(R[node], mid + 1, r, ql, qr);
t[node] = t[L[node]]+t[R[node]];
}
int getans(int node, int l,int r,int ql,int qr)
{
init(node,l,r);
if(ql > r || qr < l) return 0;
if(ql <= l && r <= qr) return t[node];
int mid = (l + r) >> 1;
int q1, q2;
if(L[node])
q1 = getans(L[node],l,mid,ql,qr);
else
q1 = 0;
if(R[node])
q2 = getans(R[node], mid + 1, r, ql,qr);
else
q2 = 0;
return q1 + q2;
}
signed main() {
OPT
int m;
cin >> m;
int c = 0;
while(m--)
{
int t,a,b;
cin >> t >> a >> b;
a += c;
b += c;
if(t == 2)
upd(1,1,N,a,b);
else
{
int ans = getans(1,1,N,a,b);
cout << ans << endl;
c = ans;
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |