Submission #488964

#TimeUsernameProblemLanguageResultExecution timeMemory
488964keta_tsimakuridzeSegments (IZhO18_segments)C++14
100 / 100
2259 ms20816 KiB
#include<bits/stdc++.h> #define f first #define s second #define pii pair<int,int> using namespace std; const int N = 2e5 + 5, mod = 1e9 + 7; // ! int t, block[N], le[N], ri[N], mink[N], Bl = 1500,removed[N]; vector<pii> all, cur, L[205], R[205]; vector<pii> _(vector<pii> x) { vector<pii> new_; for(int i = 0; i < x.size(); i++) { if(!removed[x[i].s]) new_.push_back(x[i]); } return new_; } void insert(int l,int r,int id) { cur.push_back({r - l + 1, id}); block[id] = -1; if(cur.size() == Bl) { for(int j = 0; j < cur.size(); j++) all.push_back(cur[j]); all = _(all); cur.clear(); sort(all.rbegin(), all.rend()); for(int j = 0; j <= (all.size())/Bl; j++) L[j].clear(), R[j].clear(); for(int j = 0; j < all.size(); j++) { int bl = j / Bl; L[bl].push_back({le[all[j].s], all[j].s}); R[bl].push_back({ri[all[j].s], all[j].s}); block[all[j].s] = bl; } for(int i = 0; i <= (all.size())/Bl; i++) { sort(L[i].begin(), L[i].end()); mink[i] = 2e9 + 33; for(int k = 0; k < L[i].size(); k++) mink[i] = min(mink[i], ri[L[i][k].s] - le[L[i][k].s] + 1); sort(R[i].begin(), R[i].end()); } } } vector<pii> erase(vector<pii> cur, int id) { vector<pii> new_; for(int i = 0; i < cur.size(); i++) { if(cur[i].s != id) new_.push_back(cur[i]); } return new_; } void remove(int id) { removed[id] = 1; if(block[id] == -1) { cur = erase(cur, id); return; } L[block[id]] = erase(L[block[id]], id); R[block[id]] = erase(R[block[id]], id); return; } int get(int l,int r,int k) { if(r - l + 1 < k) return 0; int cnt = 0; for(int i = 0; i < cur.size(); i++) { int id = cur[i].s; if(min(ri[id], r) - max(le[id],l) + 1 >= k) cnt++; } for(int j = 0; j <= (all.size()) / Bl; j++) { if(!L[j].size()) continue; if(mink[j] >= k) { pii p; cnt += L[j].size(); p = {r - k + 1, 1e7}; cnt -= L[j].size() - (upper_bound(L[j].begin(), L[j].end(), p) - L[j].begin()); p = {l + k - 1, -1}; cnt -= (upper_bound(R[j].begin(), R[j].end(), p) - R[j].begin()) ; } else { for(int i = 0; i < L[j].size(); i++) { int id = L[j][i].s; if(min(ri[id], r) - max(le[id],l) + 1 >= k) cnt++; } break; } } //if((r - l + 1) == k) return cnt/2; return cnt; } int get(int x,int xo) { x = x ^ (t * xo); return x; } main() { ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0); #define endl " " int n; cin >> n >> t; int xo = 0, idx = -1; for(int i = 1; i <= n; i++) { int type; cin >> type; if(type == 1) { int l,r; cin >> l >> r; l = get(l, xo), r = get(r, xo); if(l >= r) swap(l, r); le[++idx] = l; ri[idx] = r; insert(l,r,idx); } else if(type == 2) { int id; cin >> id; remove(id - 1); } else { int l,r,k; cin >> l >> r >> k; l = get(l, xo), r = get(r, xo); if(l > r) swap(l, r); xo = get(l,r,k); cout << xo << endl; } } }

Compilation message (stderr)

segments.cpp: In function 'std::vector<std::pair<int, int> > _(std::vector<std::pair<int, int> >)':
segments.cpp:11:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |  for(int i = 0; i < x.size(); i++) {
      |                 ~~^~~~~~~~~~
segments.cpp: In function 'void insert(int, int, int)':
segments.cpp:19:16: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   19 |  if(cur.size() == Bl) {
      |     ~~~~~~~~~~~^~~~~
segments.cpp:20:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |   for(int j = 0; j < cur.size(); j++) all.push_back(cur[j]);
      |                  ~~^~~~~~~~~~~~
segments.cpp:24:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |   for(int j = 0; j <= (all.size())/Bl; j++) L[j].clear(), R[j].clear();
      |                  ~~^~~~~~~~~~~~~~~~~~
segments.cpp:25:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |   for(int j = 0; j < all.size(); j++) {
      |                  ~~^~~~~~~~~~~~
segments.cpp:31:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |   for(int i = 0; i <= (all.size())/Bl; i++) {
      |                  ~~^~~~~~~~~~~~~~~~~~
segments.cpp:34:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |    for(int k = 0; k < L[i].size(); k++) mink[i] = min(mink[i], ri[L[i][k].s] - le[L[i][k].s] + 1);
      |                   ~~^~~~~~~~~~~~~
segments.cpp: In function 'std::vector<std::pair<int, int> > erase(std::vector<std::pair<int, int> >, int)':
segments.cpp:41:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |   for(int i = 0; i < cur.size(); i++) {
      |                  ~~^~~~~~~~~~~~
segments.cpp: In function 'int get(int, int, int)':
segments.cpp:59:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |  for(int i = 0; i < cur.size(); i++) {
      |                 ~~^~~~~~~~~~~~
segments.cpp:63:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |  for(int j = 0; j <= (all.size()) / Bl; j++) {
      |                 ~~^~~~~~~~~~~~~~~~~~~~
segments.cpp:74:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |    for(int i = 0; i < L[j].size(); i++) {
      |                   ~~^~~~~~~~~~~~~
segments.cpp: At global scope:
segments.cpp:88:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   88 | main() {
      | ^~~~
#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...