제출 #633849

#제출 시각아이디문제언어결과실행 시간메모리
633849fabijan_cikacSegments (IZhO18_segments)C++17
0 / 100
5078 ms5036 KiB
#include <bits/stdc++.h> using namespace std; #define pp pair<int, int> #define ppp pair<int, pp> #define F first #define S second #define pb push_back const int N = 2 * 1e5 + 100; const int BK = 400; const int INF = 2 * 1e9 + 10; int n, t; int buck = 0; vector<ppp> a[BK]; vector<ppp> b[BK]; vector<ppp> trash; vector<ppp> trash2; pp xy[N]; vector<int> L[BK][2]; vector<int> R[BK][2]; vector<ppp> st; void move_trash(){ st.clear(); for (auto i: trash) st.pb(i); trash.clear(); for (int i = 0; i < BK; ++i){ for (auto j: a[i]) st.pb(j); a[i].clear(); L[i][0].clear(); R[i][0].clear(); } for (int i = 0; i < st.size(); ++i){ a[i / buck].pb(st[i]); L[i / buck][0].pb(st[i].S.F); R[i / buck][0].pb(st[i].S.S); } } void move_trash2(){ st.clear(); for (auto i: trash2) st.pb(i); trash2.clear(); for (int i = 0; i < BK; ++i){ for (auto j: b[i]) st.pb(j); b[i].clear(); L[i][1].clear(); R[i][1].clear(); } for (int i = 0; i < st.size(); ++i){ b[i / buck].pb(st[i]); L[i / buck][1].pb(st[i].S.F); R[i / buck][1].pb(st[i].S.S); } } int bins_a(int l, int r, int k){ if (l == r) return l; int mid = (l + r + 1) / 2; if (a[mid].empty() || a[mid].back().F >= k) return bins_a(l, mid - 1, k); return bins_a(mid, r, k); } int bins_b(int l, int r, int k){ if (l == r) return l; int mid = (l + r + 1) / 2; if (b[mid].empty() || b[mid].back().F >= k) return bins_a(l, mid - 1, k); return bins_a(mid, r, k); } int bins_R(int x, int fl, int val, int l, int r){ if (l == r) return l; int mid = (l + r + 1) / 2; if (R[x][fl][mid] < val) return bins_R(x, fl, val, mid, r); return bins_R(x, fl, val, l, mid - 1); } int bins_L(int x, int fl, int val, int l, int r){ if (l == r) return l; int mid = (l + r - 1) / 2; if (L[x][fl][mid] > val) return bins_L(x, fl, val, l, mid); return bins_L(x, fl, val, mid + 1, r); } //if intersect bool inct(int l1, int r1, int l2, int r2, int k){ if (l1 > l2){ swap(l1, l2); swap(r1, r2); } r1 = min(r1, r2); if ((r1 - l2 + 1) >= k) return 1; return 0; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> t; int id = 1; buck = n / BK; int lastans = 0; int cnt = 0; for (int i = 0; i < n; ++i){ int u; cin >> u; if (id % BK == 0){ move_trash(); move_trash2(); } if (u == 1){ int l, r; cin >> l >> r; l = (l ^ (t * lastans)); r = (r ^ (t * lastans)); if (l > r) swap(l, r); trash.pb({r - l + 1, {l, r}}); sort(trash.begin(), trash.end()); xy[id] = {l, r}; ++id; } else if (u == 2){ int id; cin >> id; trash2.pb({xy[id].S - xy[id].F + 1, xy[id]}); sort(trash2.begin(), trash2.end()); } else{ int l, r, k; cin >> l >> r >> k; l = (l ^ (t * lastans)); r = (r ^ (t * lastans)); if (l > r) swap(l, r); int ans = 0; for (auto x: trash){ if (inct(l, r, x.S.F, x.S.S, k)) ++ans; } for (auto x: trash2){ if (inct(l, r, x.S.F, x.S.S, k)) --ans; } int pos1 = bins_a(0, BK - 1, k) + 1; if (a[0].empty() || a[0][0].F >= k) pos1 = 0; for (auto x: a[pos1]){ if (inct(l, r, x.S.F, x.S.S, k)) ++ans; } int pos2 = bins_b(0, BK - 1, k) + 1; if (b[0].empty() || b[0][0].F >= k) pos2 = 0; for (auto x: b[pos1]){ if (inct(l, r, x.S.F, x.S.S, k)) --ans; } for (int i = pos1; i < BK; ++i){ if (a[i].empty()) break; int num = a[i].size(); num -= bins_L(i, 0, r - k + 1, 0, L[i][0].size() - 1); num -= bins_R(i, 0, l + k - 1, 0, R[i][0].size() - 1); ans += num; } for (int i = pos2; i < BK; ++i){ if (b[i].empty()) break; int num = b[i].size(); num -= bins_L(i, 1, r - k + 1, 0, L[i][1].size() - 1); num -= bins_R(i, 1, l + k - 1, 0, R[i][1].size() - 1); ans -= num; } lastans = ans; cout << ans << '\n'; } } return 0; }

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

segments.cpp: In function 'void move_trash()':
segments.cpp:33:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     for (int i = 0; i < st.size(); ++i){
      |                     ~~^~~~~~~~~~~
segments.cpp: In function 'void move_trash2()':
segments.cpp:48:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     for (int i = 0; i < st.size(); ++i){
      |                     ~~^~~~~~~~~~~
segments.cpp: In function 'int main()':
segments.cpp:102:26: warning: unused variable 'cnt' [-Wunused-variable]
  102 |     int lastans = 0; int cnt = 0;
      |                          ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...