답안 #927305

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
927305 2024-02-14T16:56:18 Z cadmiumsky Segments (IZhO18_segments) C++17
7 / 100
5000 ms 8900 KB
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;

using ll = long long;
using ld = long double;

//#define int ll
#define sz(x) ((int)(x).size())

using pii = pair<int,int>;
using tii = tuple<int,int,int>;

const int nmax = 2e5 + 5;

pii segments[nmax];

struct Oper {
  int type;
  int a, b;
  int k;
};

namespace Precalc {
  
  multiset<pii> actives;
  
  void rebatch(vector<Oper> opqueue) {
    for(auto [t, a, b, k] : opqueue) {
      if(t == 1)
        actives.insert(pii{a, b});
      else if(t == 2)
        actives.erase(actives.find(segments[a]));
    }
    
    //for(auto [a, b] : actives) cerr << a << ' ' << b << '\n';
    //cerr << "--\n";
    
    return;
  }
  
  void contextualize(vector<int> Ks) {
    // ..
  }
  
  int query_K(int k) { 
    int cnt = 0;
    for(auto [a, b] : actives) cnt += (b - a + 1) >= k;
    return cnt;
  }
  int query_L(int L, int k) {
    int cnt = 0;
    for(auto [a, b] : actives) cnt += (b - a + 1 >= k) && (b <= L);
    return cnt;
  }
  
  int query_R(int R, int k) {
    int cnt = 0;
    for(auto [a, b] : actives) cnt += (b - a + 1 >= k) && (a >= R);
    return cnt;
  }
}

int segmpoz = 1;

int unitValue(int l, int r, int a, int b, int k) {
  return min(r, b) - max(l, a) + 1 >= k;
}

signed main() {
  cin.tie(0) -> sync_with_stdio(0);
  int n, t_offline;
  cin >> n >> t_offline;
  
  const int idealBuck = min(5., ceil(sqrt(n * log2(n))));
  const ll worstInner = (ll)ceil(idealBuck / 2) * ceil(idealBuck / 2) + 5;
  
  
  vector<Oper> operation_queue;

  int lastans = 0;
  
  auto flush_queue = [&]() {
    vector<int> Ks;
    for(auto [t, a, b, k] : operation_queue)
      if(t == 3) Ks.emplace_back(k);
    
    sort(all(Ks));
    Ks.erase(unique(all(Ks)), Ks.end());
    
    Precalc::contextualize(Ks);
    
    for(int i = 0; i < sz(operation_queue); i++) {
      auto &[ti, ai, bi, ki] = operation_queue[i];
      if(ti == 1 || ti == 3) {
        ai = ai ^ (t_offline * lastans);
        bi = bi ^ (t_offline * lastans);
        if(ai > bi) swap(ai, bi);
      }
      
      if(ti == 1)
        segments[segmpoz++] = pii{ai, bi};
      
      if(ti == 3) {
        if(bi - ai + 1 < ki) {
          lastans = 0;
        }
        else {
          int rez = Precalc::query_K(ki) - Precalc::query_R(bi - ki + 1 + 1, ki) - Precalc::query_L(ai + ki - 1 - 1, ki);
          //cerr << "? " << ai << ' ' << bi << '\t' << rez << '\n';
          for(int j = i - 1; j >= 0; j--) {
            auto &[tj, aj, bj, kj] = operation_queue[j];
            
            if(tj == 3) continue;
            
            //cerr << tj << aj << ' ' << bj << '\n';
            else if(tj == 2)
              rez -= unitValue(ai, bi, segments[aj].first, segments[aj].second, ki);
            else
              rez += unitValue(ai, bi, aj, bj, ki);
          }
          lastans = rez;
        }
        cout << lastans << '\n';
      }
    }
    
    Precalc::rebatch(operation_queue);
    operation_queue.clear();
  };
  int cnt[2] = {1, 0};
  
  for(int t, a, b, k, tc = 0; tc < n; tc++) {
    cin >> t;
    if(t == 1) {
       cin >> a >> b;
       operation_queue.emplace_back(Oper{t, a, b, -1});
       cnt[0]++;
    }
    if(t == 2) {
       cin >> a;
       operation_queue.emplace_back(Oper{t, a, -1, -1});
       cnt[0]++;
    }
    if(t == 3) {
       cin >> a >> b >> k;
       operation_queue.emplace_back(Oper{t, a, b, k});
       cnt[1]++;
    }
    
    if(tc == n - 1 || (ll)cnt[0] * cnt[1] >= worstInner) {
      flush_queue();
      
      cnt[0] = 1;
      cnt[1] = 0;
    }
  }
  
  return 0;
}

/**
  Anul asta nu se da centroid
  -- Rugaciunile mele
*/

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 4 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 106 ms 936 KB Output is correct
6 Correct 148 ms 888 KB Output is correct
7 Correct 14 ms 616 KB Output is correct
8 Correct 53 ms 732 KB Output is correct
9 Correct 49 ms 604 KB Output is correct
10 Correct 25 ms 856 KB Output is correct
11 Correct 146 ms 808 KB Output is correct
12 Correct 148 ms 816 KB Output is correct
13 Correct 29 ms 860 KB Output is correct
14 Correct 49 ms 604 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 3 ms 592 KB Output is correct
17 Correct 30 ms 600 KB Output is correct
18 Correct 39 ms 856 KB Output is correct
19 Correct 37 ms 680 KB Output is correct
20 Correct 33 ms 956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5005 ms 5964 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 96 ms 2644 KB Output is correct
2 Correct 53 ms 2488 KB Output is correct
3 Correct 178 ms 2672 KB Output is correct
4 Correct 66 ms 2532 KB Output is correct
5 Execution timed out 5026 ms 8260 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 2900 KB Output is correct
2 Correct 68 ms 2644 KB Output is correct
3 Correct 57 ms 2640 KB Output is correct
4 Correct 77 ms 2644 KB Output is correct
5 Execution timed out 5028 ms 8900 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 4 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 106 ms 936 KB Output is correct
6 Correct 148 ms 888 KB Output is correct
7 Correct 14 ms 616 KB Output is correct
8 Correct 53 ms 732 KB Output is correct
9 Correct 49 ms 604 KB Output is correct
10 Correct 25 ms 856 KB Output is correct
11 Correct 146 ms 808 KB Output is correct
12 Correct 148 ms 816 KB Output is correct
13 Correct 29 ms 860 KB Output is correct
14 Correct 49 ms 604 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 3 ms 592 KB Output is correct
17 Correct 30 ms 600 KB Output is correct
18 Correct 39 ms 856 KB Output is correct
19 Correct 37 ms 680 KB Output is correct
20 Correct 33 ms 956 KB Output is correct
21 Execution timed out 5005 ms 5964 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 4 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 106 ms 936 KB Output is correct
6 Correct 148 ms 888 KB Output is correct
7 Correct 14 ms 616 KB Output is correct
8 Correct 53 ms 732 KB Output is correct
9 Correct 49 ms 604 KB Output is correct
10 Correct 25 ms 856 KB Output is correct
11 Correct 146 ms 808 KB Output is correct
12 Correct 148 ms 816 KB Output is correct
13 Correct 29 ms 860 KB Output is correct
14 Correct 49 ms 604 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 3 ms 592 KB Output is correct
17 Correct 30 ms 600 KB Output is correct
18 Correct 39 ms 856 KB Output is correct
19 Correct 37 ms 680 KB Output is correct
20 Correct 33 ms 956 KB Output is correct
21 Execution timed out 5005 ms 5964 KB Time limit exceeded
22 Halted 0 ms 0 KB -