제출 #924815

#제출 시각아이디문제언어결과실행 시간메모리
924815Karoot원숭이와 사과 나무 (IZhO12_apple)C++17
100 / 100
178 ms153900 KiB
#include <iostream> #include <cmath> #include <unordered_map> #include <map> #include <set> #include <queue> #include <vector> #include <string> #include <iomanip> #include <algorithm> #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() using namespace std; typedef long long ll; ll linf = 1e15+1; inline void scoobydoobydoo(){ ios::sync_with_stdio(false); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } struct Node { ll sum; bool lzSet; int l, r; Node() : sum(0), lzSet(0), l(-1), r(-1) {} }; const int MAXN = 1e5+1; Node ST[64*MAXN]; int cnt = 2; void pushup(int p){ ST[p].sum = (ST[ST[p].l].sum + ST[ST[p].r].sum); } void pushdown(int p, int l, int r){ int mid = (l+r)/2; int a = ST[p].l, b = ST[p].r; ST[a].lzSet |= ST[p].lzSet; ST[b].lzSet |= ST[p].lzSet; ST[a].sum = (ST[a].lzSet ? (mid-l+1) : ST[a].sum); ST[b].sum = (ST[b].lzSet ? (r - mid) : ST[b].sum); ST[p].lzSet = 0; return; } void update(int p, int l, int r, int a, int b){ if (a == l && b == r){ ST[p].sum = r-l+1; ST[p].lzSet = 1; return; } int mid = (l+r)/2; if (ST[p].l == -1){ ST[p].l = cnt++; ST[ST[p].l]; } if (ST[p].r == -1){ ST[p].r = cnt++; ST[ST[r].l]; } pushdown(p, l, r); if (b <= mid){ update(ST[p].l, l, mid, a, b); } else if (a >= mid+1){ update(ST[p].r, mid+1, r, a, b); } else { update(ST[p].l, l, mid, a, mid); update(ST[p].r, mid+1, r, mid+1, b); } pushup(p); return; } ll query(int p, int l, int r, int a, int b) { if (a == l && r == b) return ST[p].sum; int mid = (l + r) >> 1; if (ST[p].l == -1){ ST[p].l = cnt++; ST[ST[p].l]; } if (ST[p].r == -1){ ST[p].r = cnt++; ST[ST[r].l]; } pushdown(p, l, r); if (b <= mid){ return query(ST[p].l, l, mid, a, b); } if (a >= mid+1){ return query(ST[p].r, mid+1, r, a, b); } return query(ST[p].l, l, mid, a, mid) + query(ST[p].r, mid + 1, r, mid+1, b); } int main(){ scoobydoobydoo(); int q; cin >> q; vector<ll> ans; ST[1]; ll C = 0; while (q--){ int t, x, y; cin >> t >> x >> y; if (t == 2){ update(1, 0, 1e9, x+C, y+C); } else { ans.push_back(query(1, 0, 1e9, x+C, y+C)); C = ans[ans.size()-1]; } } for (auto& e : ans){ cout << e << "\n"; } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

apple.cpp: In function 'void update(int, int, int, int, int)':
apple.cpp:63:19: warning: statement has no effect [-Wunused-value]
   63 |         ST[ST[p].l];
      |         ~~~~~~~~~~^
apple.cpp:67:19: warning: statement has no effect [-Wunused-value]
   67 |         ST[ST[r].l];
      |         ~~~~~~~~~~^
apple.cpp: In function 'll query(int, int, int, int, int)':
apple.cpp:88:19: warning: statement has no effect [-Wunused-value]
   88 |         ST[ST[p].l];
      |         ~~~~~~~~~~^
apple.cpp:92:19: warning: statement has no effect [-Wunused-value]
   92 |         ST[ST[r].l];
      |         ~~~~~~~~~~^
apple.cpp: In function 'int main()':
apple.cpp:111:9: warning: statement has no effect [-Wunused-value]
  111 |     ST[1];
      |     ~~~~^
#Verdict Execution timeMemoryGrader output
Fetching results...