Submission #38717

#TimeUsernameProblemLanguageResultExecution timeMemory
38717TalantMonkey and Apple-trees (IZhO12_apple)C++14
100 / 100
603 ms122328 KiB
#include <bits/stdc++.h> #define fr first #define sc second #define OK puts("OK"); #define pb push_back #define mk make_pair using namespace std; typedef long long ll; const int inf = (int)1e9 + 7; const int N = (int)7e6 + 7e5; int n; int type,x,y,c; int cnt = 1; struct node { int l,r,sum,add; node () { l = r = add = sum = 0; } }t[N]; void push (int v,int tl,int tr) { if (t[v].add != 0) { if (!t[v].l) t[v].l = ++cnt; if (!t[v].r) t[v].r = ++cnt; t[t[v].l].add = t[v].add; t[t[v].r].add = t[v].add; t[v].sum = (tr - tl + 1); } t[v].add = 0; } void update (int l,int r,int v = 1,int tl = 1,int tr = 1e9 + 7) { if (tl > r || tr < l) return; if (t[v].add != 0) push (v,tl,tr); if (l <= tl && tr <= r) { t[v].add = 1; } else { int tm = (tl + tr) >> 1; if (t[v].l == 0) t[v].l = ++cnt; if (t[v].r == 0) t[v].r = ++cnt; update (l,r,t[v].l,tl,tm); update (l,r,t[v].r,tm + 1,tr); push (v,tl,tr); push (t[v].l,tl,tm); push (t[v].r,tm + 1,tr); t[v].sum = t[t[v].l].sum + t[t[v].r].sum; } } int get (int l,int r,int v = 1,int tl = 1,int tr = 1e9 + 7) { if (tl > r || tr < l) return 0; push (v,tl,tr); if (l <= tl && tr <= r) return t[v].sum; int tm = (tl + tr) >> 1; return get (l,r,t[v].l,tl,tm) + get(l,r,t[v].r,tm + 1,tr); } int main () { scanf ("%d", &n); for (int i = 1; i <= n; i ++) { scanf ("%d%d%d", &type,&x,&y); x += c; y += c; if (type == 1) { c = get(x,y); printf("%d\n", c); } else { update (x,y); } } }

Compilation message (stderr)

apple.cpp: In function 'int main()':
apple.cpp:79:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf ("%d", &n);
                         ^
apple.cpp:82:46: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
                 scanf ("%d%d%d", &type,&x,&y);
                                              ^
#Verdict Execution timeMemoryGrader output
Fetching results...