Submission #633987

#TimeUsernameProblemLanguageResultExecution timeMemory
633987fabijan_cikacSegments (IZhO18_segments)C++17
Compilation error
0 ms0 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 = 300; const int INF = 2 * 1e9 + 10; int n, t; int buck = 0; vector<ppp> a[BK]; int divs[N]; vector<ppp> b[BK]; vector<ppp> trash; vector<ppp> trash2; pp xy[N]; vector<int> L[2][BK]; vector<int> R[2][BK]; vector<ppp> st; void move_trash(){ st.clear(); sort(trash.begin(), trash.end()); int cnt = 0; for (int i = 0; i < BK; ++i){ if (a[i].empty()) break; for (int j = 0; j < a[i].size(); ++j){ while (cnt < trash.size() && trash[cnt].F <= a[i][j].F){ st.pb(trash[cnt]); ++cnt; } st.pb(a[i][j]); } a[i].clear(); L[0][i].clear(); R[0][i].clear(); } while (cnt < trash.size()){ st.pb(trash[cnt]); ++cnt; } trash.clear(); sort(st.begin(), st.end()); for (int i = 0; i < st.size(); ++i){ a[divs[i]].pb(st[i]); L[0][divs[i]].pb(st[i].S.F); R[0][divs[i]].pb(st[i].S.S); } for (int i = 0; i < BK; ++i){ if (L[0][i].empty()) return; sort(L[0][i].begin(), L[0][i].end()); sort(R[0][i].begin(), R[0][i].end()); } } void move_trash2(){ st.clear(); sort(trash2.begin(), trash2.end()); int cnt = 0; for (int i = 0; i < BK; ++i){ if (b[i].empty()) continue; for (int j = 0; j < b[i].size(); ++j){ while (cnt < trash2.size() && trash2[cnt].F <= a[i][j].F){ st.pb(trash2[cnt]); ++cnt; } st.pb(b[i][j]); } b[i].clear(); L[1][i].clear(); R[1][i].clear(); } while (cnt < trash2.size()){ st.pb(trash2[cnt]); ++cnt; } trash2.clear(); sort(st.begin(), st.end()); for (int i = 0; i < st.size(); ++i){ b[divs[i]].pb(st[i]); L[1][divs[i]].pb(st[i].S.F); R[1][divs[i]].pb(st[i].S.S); } for (int i = 0; i < BK; ++i){ if (L[1][i].empty()) return; sort(L[1][i].begin(), L[1][i].end()); sort(R[1][i].begin(), R[1][i].end()); } } 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_b(l, mid - 1, k); return bins_b(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[fl][x][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[fl][x][mid] > val) return bins_L(x, fl, val, l, mid); return bins_L(x, fl, val, mid + 1, r); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> t; buck = n / BK + 1; int lastans = 0; int cnt = 1; int id = 1; for (int i = 0; i < N; ++i) divs[i] = i / buck; for (int i = 0; i < n; ++i){ int u; cin >> u; if (cnt % buck == 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}; ++cnt; ++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()); ++cnt; } else{ int l, r, k; cin >> l >> r >> k; l = (l ^ (t * lastans)); r = (r ^ (t * lastans)); if (l > r) swap(l, r); if (k > r - l + 1){ cout << 0 << '\n'; lastans = 0; continue; } int ans = 0; for (ppp x: trash){ if (min(r, x.S.S) - max(x.S.F, l) + 1 >= k) ++ans; } for (ppp x: trash2){ if (min(r, x.S.S) - max(x.S.F, l) + 1 >= k) --ans; } int pos1 = bins_a(0, BK - 1, k) + 1; if (a[0].empty() || a[0].back().F >= k) pos1 = 0; for (ppp x: a[pos1]){ if (min(r, x.S.S) - max(x.S.F, l) + 1 >= k) ++ans; } int pos2 = bins_b(0, BK - 1, k) + 1; if (b[0].empty() || b[0].back().F >= k) pos2 = 0; for (auto x: b[pos2]){ if (min(r, x.S.S) - max(x.S.F, l) + 1 >= k) --ans; } for (int i = pos1 + 1; i < BK; ++i){ if (a[i].empty()) break; int num = a[i].size(); if (L[0][i].back() > r - k + 1) num -= (L[0][i].size() - bins_L(i, 0, r - k + 1, 0, L[0][i].size() - 1)); if (R[0][i][0] < l + k - 1) num -= (bins_R(i, 0, l + k - 1, 0, R[0][i].size() - 1) + 1); ans += num; } for (int i = pos2 + 1; i < BK; ++i){ if (b[i].empty()) break; int num = b[i].size(); if (L[1][i].back() > r - k + 1) num -= (L[1][i].size() - bins_L(i, 1, r - k + 1, 0, L[1][i].size() - 1)); if (R[1][i][0] < l + k - 1) num -= (bins_R(i, 1, l + k - 1, 0, R[1][i].size() - 1) + 1); ans -= num; } lastans = ans; cout << ans << '\n'; } } return 0; } #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 = 300; const int INF = 2 * 1e9 + 10; int n, t; int buck = 0; vector<ppp> a[BK]; int divs[N]; vector<ppp> b[BK]; vector<ppp> trash; vector<ppp> trash2; pp xy[N]; vector<int> L[2][BK]; vector<int> R[2][BK]; vector<ppp> st; void move_trash(){ st.clear(); sort(trash.begin(), trash.end()); int cnt = 0; for (int i = 0; i < BK; ++i){ if (a[i].empty()) break; for (int j = 0; j < a[i].size(); ++j){ while (cnt < trash.size() && trash[cnt].F <= a[i][j].F){ st.pb(trash[cnt]); ++cnt; } st.pb(a[i][j]); } a[i].clear(); L[0][i].clear(); R[0][i].clear(); } while (cnt < trash.size()){ st.pb(trash[cnt]); ++cnt; } trash.clear(); sort(st.begin(), st.end()); for (int i = 0; i < st.size(); ++i){ a[divs[i]].pb(st[i]); L[0][divs[i]].pb(st[i].S.F); R[0][divs[i]].pb(st[i].S.S); } for (int i = 0; i < BK; ++i){ if (L[0][i].empty()) return; sort(L[0][i].begin(), L[0][i].end()); sort(R[0][i].begin(), R[0][i].end()); } } void move_trash2(){ st.clear(); sort(trash2.begin(), trash2.end()); int cnt = 0; for (int i = 0; i < BK; ++i){ if (b[i].empty()) continue; for (int j = 0; j < b[i].size(); ++j){ while (cnt < trash2.size() && trash2[cnt].F <= a[i][j].F){ st.pb(trash2[cnt]); ++cnt; } st.pb(b[i][j]); } b[i].clear(); L[1][i].clear(); R[1][i].clear(); } while (cnt < trash2.size()){ st.pb(trash2[cnt]); ++cnt; } trash2.clear(); sort(st.begin(), st.end()); for (int i = 0; i < st.size(); ++i){ b[divs[i]].pb(st[i]); L[1][divs[i]].pb(st[i].S.F); R[1][divs[i]].pb(st[i].S.S); } for (int i = 0; i < BK; ++i){ if (L[1][i].empty()) return; sort(L[1][i].begin(), L[1][i].end()); sort(R[1][i].begin(), R[1][i].end()); } } 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_b(l, mid - 1, k); return bins_b(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[fl][x][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[fl][x][mid] > val) return bins_L(x, fl, val, l, mid); return bins_L(x, fl, val, mid + 1, r); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> t; buck = n / BK + 1; int lastans = 0; int cnt = 1; int id = 1; for (int i = 0; i < N; ++i) divs[i] = i / buck; for (int i = 0; i < n; ++i){ int u; cin >> u; if (cnt % buck == 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}; ++cnt; ++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()); ++cnt; } else{ int l, r, k; cin >> l >> r >> k; l = (l ^ (t * lastans)); r = (r ^ (t * lastans)); if (l > r) swap(l, r); if (k > r - l + 1){ cout << 0 << '\n'; lastans = 0; continue; } int ans = 0; for (ppp x: trash){ if (min(r, x.S.S) - max(x.S.F, l) + 1 >= k) ++ans; } for (ppp x: trash2){ if (min(r, x.S.S) - max(x.S.F, l) + 1 >= k) --ans; } int pos1 = bins_a(0, BK - 1, k) + 1; if (a[0].empty() || a[0].back().F >= k) pos1 = 0; for (ppp x: a[pos1]){ if (min(r, x.S.S) - max(x.S.F, l) + 1 >= k) ++ans; } int pos2 = bins_b(0, BK - 1, k) + 1; if (b[0].empty() || b[0].back().F >= k) pos2 = 0; for (auto x: b[pos2]){ if (min(r, x.S.S) - max(x.S.F, l) + 1 >= k) --ans; } for (int i = pos1 + 1; i < BK; ++i){ if (a[i].empty()) break; int num = a[i].size(); if (L[0][i].back() > r - k + 1) num -= (L[0][i].size() - bins_L(i, 0, r - k + 1, 0, L[0][i].size() - 1)); if (R[0][i][0] < l + k - 1) num -= (bins_R(i, 0, l + k - 1, 0, R[0][i].size() - 1) + 1); ans += num; } for (int i = pos2 + 1; i < BK; ++i){ if (b[i].empty()) break; int num = b[i].size(); if (L[1][i].back() > r - k + 1) num -= (L[1][i].size() - bins_L(i, 1, r - k + 1, 0, L[1][i].size() - 1)); if (R[1][i][0] < l + k - 1) num -= (bins_R(i, 1, l + k - 1, 0, R[1][i].size() - 1) + 1); ans -= num; } lastans = ans; cout << ans << '\n'; } } return 0; }

Compilation message (stderr)

segments.cpp: In function 'void move_trash()':
segments.cpp:29:27: 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]
   29 |         for (int j = 0; j < a[i].size(); ++j){
      |                         ~~^~~~~~~~~~~~~
segments.cpp:30:24: 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]
   30 |             while (cnt < trash.size() && trash[cnt].F <= a[i][j].F){
      |                    ~~~~^~~~~~~~~~~~~~
segments.cpp:37:16: 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]
   37 |     while (cnt < trash.size()){
      |            ~~~~^~~~~~~~~~~~~~
segments.cpp:41: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]
   41 |     for (int i = 0; i < st.size(); ++i){
      |                     ~~^~~~~~~~~~~
segments.cpp: In function 'void move_trash2()':
segments.cpp:58:27: 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]
   58 |         for (int j = 0; j < b[i].size(); ++j){
      |                         ~~^~~~~~~~~~~~~
segments.cpp:59:24: 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]
   59 |             while (cnt < trash2.size() && trash2[cnt].F <= a[i][j].F){
      |                    ~~~~^~~~~~~~~~~~~~~
segments.cpp:66:16: 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]
   66 |     while (cnt < trash2.size()){
      |            ~~~~^~~~~~~~~~~~~~~
segments.cpp:70: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]
   70 |     for (int i = 0; i < st.size(); ++i){
      |                     ~~^~~~~~~~~~~
segments.cpp: At global scope:
segments.cpp:201:11: error: redefinition of 'const int N'
  201 | const int N = 2 * 1e5 + 100;
      |           ^
segments.cpp:11:11: note: 'const int N' previously defined here
   11 | const int N = 2 * 1e5 + 100;
      |           ^
segments.cpp:202:11: error: redefinition of 'const int BK'
  202 | const int BK = 300;
      |           ^~
segments.cpp:12:11: note: 'const int BK' previously defined here
   12 | const int BK = 300;
      |           ^~
segments.cpp:203:11: error: redefinition of 'const int INF'
  203 | const int INF = 2 * 1e9 + 10;
      |           ^~~
segments.cpp:13:11: note: 'const int INF' previously defined here
   13 | const int INF = 2 * 1e9 + 10;
      |           ^~~
segments.cpp:205:5: error: redefinition of 'int n'
  205 | int n, t; int buck = 0;
      |     ^
segments.cpp:15:5: note: 'int n' previously declared here
   15 | int n, t; int buck = 0;
      |     ^
segments.cpp:205:8: error: redefinition of 'int t'
  205 | int n, t; int buck = 0;
      |        ^
segments.cpp:15:8: note: 'int t' previously declared here
   15 | int n, t; int buck = 0;
      |        ^
segments.cpp:205:15: error: redefinition of 'int buck'
  205 | int n, t; int buck = 0;
      |               ^~~~
segments.cpp:15:15: note: 'int buck' previously defined here
   15 | int n, t; int buck = 0;
      |               ^~~~
segments.cpp:206:13: error: redefinition of 'std::vector<std::pair<int, std::pair<int, int> > > a [300]'
  206 | vector<ppp> a[BK]; int divs[N];
      |             ^
segments.cpp:16:13: note: 'std::vector<std::pair<int, std::pair<int, int> > > a [300]' previously declared here
   16 | vector<ppp> a[BK]; int divs[N];
      |             ^
segments.cpp:206:24: error: redefinition of 'int divs [200100]'
  206 | vector<ppp> a[BK]; int divs[N];
      |                        ^~~~
segments.cpp:16:24: note: 'int divs [200100]' previously declared here
   16 | vector<ppp> a[BK]; int divs[N];
      |                        ^~~~
segments.cpp:207:13: error: redefinition of 'std::vector<std::pair<int, std::pair<int, int> > > b [300]'
  207 | vector<ppp> b[BK];
      |             ^
segments.cpp:17:13: note: 'std::vector<std::pair<int, std::pair<int, int> > > b [300]' previously declared here
   17 | vector<ppp> b[BK];
      |             ^
segments.cpp:208:13: error: redefinition of 'std::vector<std::pair<int, std::pair<int, int> > > trash'
  208 | vector<ppp> trash;
      |             ^~~~~
segments.cpp:18:13: note: 'std::vector<std::pair<int, std::pair<int, int> > > trash' previously declared here
   18 | vector<ppp> trash;
      |             ^~~~~
segments.cpp:209:13: error: redefinition of 'std::vector<std::pair<int, std::pair<int, int> > > trash2'
  209 | vector<ppp> trash2;
      |             ^~~~~~
segments.cpp:19:13: note: 'std::vector<std::pair<int, std::pair<int, int> > > trash2' previously declared here
   19 | vector<ppp> trash2;
      |             ^~~~~~
segments.cpp:210:4: error: redefinition of 'std::pair<int, int> xy [200100]'
  210 | pp xy[N]; vector<int> L[2][BK];
      |    ^~
segments.cpp:20:4: note: 'std::pair<int, int> xy [200100]' previously defined here
   20 | pp xy[N]; vector<int> L[2][BK];
      |    ^~
segments.cpp:210:23: error: redefinition of 'std::vector<int> L [2][300]'
  210 | pp xy[N]; vector<int> L[2][BK];
      |                       ^
segments.cpp:20:23: note: 'std::vector<int> L [2][300]' previously declared here
   20 | pp xy[N]; vector<int> L[2][BK];
      |                       ^
segments.cpp:211:13: error: redefinition of 'std::vector<int> R [2][300]'
  211 | vector<int> R[2][BK];
      |             ^
segments.cpp:21:13: note: 'std::vector<int> R [2][300]' previously declared here
   21 | vector<int> R[2][BK];
      |             ^
segments.cpp:213:13: error: redefinition of 'std::vector<std::pair<int, std::pair<int, int> > > st'
  213 | vector<ppp> st;
      |             ^~
segments.cpp:23:13: note: 'std::vector<std::pair<int, std::pair<int, int> > > st' previously declared here
   23 | vector<ppp> st;
      |             ^~
segments.cpp:214:6: error: redefinition of 'void move_trash()'
  214 | void move_trash(){
      |      ^~~~~~~~~~
segments.cpp:24:6: note: 'void move_trash()' previously defined here
   24 | void move_trash(){
      |      ^~~~~~~~~~
segments.cpp: In function 'void move_trash()':
segments.cpp:219:27: 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]
  219 |         for (int j = 0; j < a[i].size(); ++j){
      |                         ~~^~~~~~~~~~~~~
segments.cpp:220:24: 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]
  220 |             while (cnt < trash.size() && trash[cnt].F <= a[i][j].F){
      |                    ~~~~^~~~~~~~~~~~~~
segments.cpp:227:16: 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]
  227 |     while (cnt < trash.size()){
      |            ~~~~^~~~~~~~~~~~~~
segments.cpp:231: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]
  231 |     for (int i = 0; i < st.size(); ++i){
      |                     ~~^~~~~~~~~~~
segments.cpp: At global scope:
segments.cpp:243:6: error: redefinition of 'void move_trash2()'
  243 | void move_trash2(){
      |      ^~~~~~~~~~~
segments.cpp:53:6: note: 'void move_trash2()' previously defined here
   53 | void move_trash2(){
      |      ^~~~~~~~~~~
segments.cpp: In function 'void move_trash2()':
segments.cpp:248:27: 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]
  248 |         for (int j = 0; j < b[i].size(); ++j){
      |                         ~~^~~~~~~~~~~~~
segments.cpp:249:24: 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]
  249 |             while (cnt < trash2.size() && trash2[cnt].F <= a[i][j].F){
      |                    ~~~~^~~~~~~~~~~~~~~
segments.cpp:256:16: 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]
  256 |     while (cnt < trash2.size()){
      |            ~~~~^~~~~~~~~~~~~~~
segments.cpp:260: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]
  260 |     for (int i = 0; i < st.size(); ++i){
      |                     ~~^~~~~~~~~~~
segments.cpp: At global scope:
segments.cpp:272:5: error: redefinition of 'int bins_a(int, int, int)'
  272 | int bins_a(int l, int r, int k){
      |     ^~~~~~
segments.cpp:82:5: note: 'int bins_a(int, int, int)' previously defined here
   82 | int bins_a(int l, int r, int k){
      |     ^~~~~~
segments.cpp:279:5: error: redefinition of 'int bins_b(int, int, int)'
  279 | int bins_b(int l, int r, int k){
      |     ^~~~~~
segments.cpp:89:5: note: 'int bins_b(int, int, int)' previously defined here
   89 | int bins_b(int l, int r, int k){
      |     ^~~~~~
segments.cpp:286:5: error: redefinition of 'int bins_R(int, int, int, int, int)'
  286 | int bins_R(int x, int fl, int val, int l, int r){
      |     ^~~~~~
segments.cpp:96:5: note: 'int bins_R(int, int, int, int, int)' previously defined here
   96 | int bins_R(int x, int fl, int val, int l, int r){
      |     ^~~~~~
segments.cpp:294:5: error: redefinition of 'int bins_L(int, int, int, int, int)'
  294 | int bins_L(int x, int fl, int val, int l, int r){
      |     ^~~~~~
segments.cpp:104:5: note: 'int bins_L(int, int, int, int, int)' previously defined here
  104 | int bins_L(int x, int fl, int val, int l, int r){
      |     ^~~~~~
segments.cpp:302:5: error: redefinition of 'int main()'
  302 | int main(){
      |     ^~~~
segments.cpp:112:5: note: 'int main()' previously defined here
  112 | int main(){
      |     ^~~~