# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
312462 | Trickster | 원숭이와 사과 나무 (IZhO12_apple) | C++14 | 331 ms | 4088 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 <algorithm>
#include <string.h>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
#include <map>
using namespace std;
#define lm (1<<30)
#define N 200010
#define ff first
#define ss second
#define ll long long
#define pb push_back
#define mod 1000000007
#define pii pair <ll, ll>
#define sz(a) int(a.size())
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
ll bigmod(ll a,ll e) {if(e==0)return 1;ll x=bigmod(a*a%mod,e>>1);return e&1?x*a%mod:x;}
int T[N], L[N], R[N];
int nodes, q, c, tp, l, r;
int lft(int node)
{
if(L[node] == -1) L[node] = ++nodes;
return L[node];
}
int rgh(int node)
{
if(R[node] == -1) R[node] = ++nodes;
return R[node];
}
void upd(int a, int b, int l, int r, int node)
{
if(l > b || r < a || T[node] == r-l+1) return;
if(l >= a && r <= b) {
T[node] = r-l+1;
return;
}
upd(a, b, l, (l+r)/2, lft(node));
upd(a, b, (l+r)/2+1, r, rgh(node));
T[node] = T[L[node]] + T[R[node]];
}
int tap(int a, int b, int l, int r, int node)
{
if(l > b || r < a || node == -1) return 0;
if(l >= a && r <= b) return T[node];
if(T[node] == r-l+1) return min(r, b) - max(l, a) + 1;
return tap(a, b, l, (l+r)/2, L[node]) + tap(a, b, (l+r)/2+1, r, R[node]);
}
int main()
{
for(int i = 0; i <= 100000; i++) L[i] = R[i] = -1;
cin >> q;
while(q--) {
cin >> tp >> l >> r;
l += c, r += c;
if(tp == 1) c = tap(l, r, 1, lm, 0), cout << c << "\n";
else upd(l, r, 1, lm, 0);
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |