Submission #90271

#TimeUsernameProblemLanguageResultExecution timeMemory
90271YottaByteMonkey and Apple-trees (IZhO12_apple)C++14
0 / 100
116 ms17124 KiB
//#include <bits/stdc++.h> #include <iostream> using namespace std; const int N = 1e6 + 1; int a[N], t[N * 4], c, h[N * 4]; void push(int v, int l, int r) { if(!h[v]) return; if(l == r) { t[v] = (r - l + 1) * h[v]; h[v] = 0; return; } else { t[v] = (r - l + 1) * h[v]; h[v + v] = h[v]; h[v + v + 1] = h[v]; h[v] = 0; return; } } void upd(int v, int l, int r, int ql, int qr) { int mid = l + r >> 1; if(r < ql || l > qr) return; if(ql <= l && r <= qr) { h[v] = 1; push(v, l, r); //puts("OUT"); //cout << l << " " << r << " "; //cout << t[v] << endl; return; } else { upd(v + v, l, mid, ql, qr); upd(v + v + 1, mid + 1, r, ql, qr); } push(v + v, l, mid); push(v + v + 1, mid + 1, r); t[v] = t[v + v] + t[v + v + 1]; } int getsum(int v, int l, int r, int ql, int qr) { push(v, l, r); if(r < ql || l > qr) return 0; if(ql <= l && r <= qr) { //cout << l << " " << r << " " << t[v] << endl; return t[v]; } else { int mid = l + r >> 1; return getsum(v + v, l, mid, ql, qr) + getsum(v + v + 1, mid + 1, r, ql, qr); } } main() { int m; cin >> m; while(m--) { int d, l, r; cin >> d >> l >> r; if(d % 2) { //cout << t[1] << endl; c = getsum(1, 1, N, l + c, r + c); cout << c << endl; } else { upd(1, 1, N, l + c, r + c); } } } /* 6 2 1 7 2 10 12 1 7 11 2 11 13 1 8 10 1 15 17 */

Compilation message (stderr)

apple.cpp: In function 'void upd(int, int, int, int, int)':
apple.cpp:30:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid = l + r >> 1;
            ~~^~~
apple.cpp: In function 'int getsum(int, int, int, int, int)':
apple.cpp:66:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int mid = l + r >> 1;
             ~~^~~
apple.cpp: At global scope:
apple.cpp:71:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
#Verdict Execution timeMemoryGrader output
Fetching results...