Submission #523455

#TimeUsernameProblemLanguageResultExecution timeMemory
523455tmn2005Monkey and Apple-trees (IZhO12_apple)C++17
0 / 100
106 ms24232 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define fr first #define sc second #define vec vector #define ret return #define ins insert #define mk make_pair #define pb push_back #define pii pair<int,int> #define all(s) s.begin(), s.end() #define allr(s) s.rbegin(), s.rend() const int N = 1e6+12, INF = 1e9, mod = 1e9+7; int lz[N*4], sum[N*4]; void push(int p, int len) { if (lz[p] != -1) { sum[p] = len * lz[p]; if (len > 1) { lz[2 * p] = lz[2 * p + 1] = lz[p]; } lz[p] = -1; } } void update(int p, int l, int r, int x, int y) { push(p, r - l + 1); if (l > y || r < x) return; if (l >= x && r <= y) { lz[p] = 1; push(p, r - l + 1); return; } int m = (l + r) / 2; update(2 * p, l, m, x, y); update(2 * p + 1, m + 1, r, x, y); sum[p] = sum[2 * p] + sum[2 * p + 1]; } int get(int p, int l, int r, int x, int y) { push(p, r - l + 1); if (l > y || r < x) return 0; if (l >= x && r <= y) { return sum[p]; } int m = (l + r) / 2; return get(2 * p, l, m, x, y) + get(2 * p + 1, m + 1, r, x, y); } main(){ int n; cin>>n; memset(lz, -1, sizeof lz); int c = 0; for(int i=1; i<=n; i++){ int z, x, y; cin>>z>>x>>y; if(z == 2){ update(1, 1, N, x + c, y + c); } else{ int ans = get(1, 1, N, x + c, y + c); cout<<ans<<"\n"; c = ans; } } return 0; }

Compilation message (stderr)

apple.cpp:54:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   54 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...