Submission #805743

# Submission time Handle Problem Language Result Execution time Memory
805743 2023-08-03T22:24:15 Z farhan132 Segments (IZhO18_segments) C++17
7 / 100
5000 ms 3312 KB
/***Farhan132***/
// #pragma GCC optimize("Ofast,fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
 
using namespace std;
 
typedef int ll;
typedef double dd;
typedef pair<ll , ll> ii;
typedef tuple < ll,  ll, ll > tp;
 
#define ff first
#define ss second
#define pb push_back
#define in insert
#define bug printf("**!\n")
#define mem(a , b) memset(a, b ,sizeof(a))
#define front_zero(n) __builtin_clz(n)
#define back_zero(n) __builtin_ctzll(n)
#define total_one(n) __builtin_popcount(n)
#define clean fflush(stdout)
 
const ll mod =  (ll) 998244353;
// const ll mod =  (ll) 1e9 + 7;
const ll inf = numeric_limits<int>::max()-1;
const ll INF = (ll)2e18;
 
// ll dx[]={0,1,0,-1};
// ll dy[]={1,0,-1,0};
// ll dxx[]={0,1,0,-1,1,1,-1,-1};
// ll dyy[]={1,0,-1,0,1,-1,1,-1};
 
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
 
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const ll N = 450;

vector < ll > R[N], sz[N];
vector < ii > req[N];
ll lx[N], rx[N]; ii range[N * N];
ll block_cnt = 1;

void add(ll l, ll r){
    for(ll block = 0; block < block_cnt; block++){
        if(lx[block] <= l){
            R[block].pb(r);
            sz[block].pb(r - l + 1);
            req[block].pb({l, r});
            for(ll i = 1; i < R[block].size(); i++){
                if(R[block][i - 1] > R[block][i]) swap(R[block][i], R[block][i - 1]);
                if(sz[block][i - 1] > sz[block][i]) swap(sz[block][i], sz[block][i - 1]);
            }
            return;
        }
    }
}
void remove(ll l, ll r){
    for(ll block = 0; block < block_cnt; block++){
        if(lx[block] <= l){
            for(ll i = 0; i < R[block].size(); i++){
                if(R[block][i] == r){
                    R[block].erase(R[block].begin() + i);
                    break;
                }
            }
            for(ll i = 0; i < sz[block].size(); i++){
                if(sz[block][i] == r - l + 1){
                    sz[block].erase(sz[block].begin() + i);
                }
            }
            for(ll i = 0; i < req[block].size(); i++){
                if(req[block][i] == make_pair(l, r)){
                    req[block].erase(req[block].begin() + i);
                }
            }
            return;
        }
    }
}
ll query(ll lastans, ll t){
    ll l, r, k; cin >> l >> r >> k;

    l ^= t * lastans;
    r ^= t * lastans;

    if(l > r) swap(l, r);
    if(r - l + 1 < k){
        return 0;
    } 

    ll ans = 0;
    if(k == 0){
        for(ll i = 0; i < block_cnt; i++) ans += req[i].size();
        return ans;
    }

    for(ll i = 0; i < block_cnt; i++){
        if(lx[i] + k - 1 > r) break;
        if(rx[i] <= l){
            ans += ((int)R[i].size() - (lower_bound(R[i].begin(), R[i].end(), l + k - 1) - R[i].begin()));
            continue;
        }
        if(l <= lx[i] && rx[i] + k - 1 <= r){
            ans += ((int)sz[i].size() - (lower_bound(sz[i].begin(), sz[i].end(), k) - sz[i].begin()));
            continue;
        }

        for(auto [x, y] : req[i]){
            ans += (min(y, r) - max(l, x) + 1 >= k);
        }
    }
    return ans;
}
void build(){
    vector < ii > a;
    for(ll i = 0; i < block_cnt; i++){
        for(auto x : req[i]) a.pb(x);
        R[i].clear(); sz[i].clear(); req[i].clear();
    }
    sort(a.begin(), a.end());
    block_cnt = (a.size() - 1) / N; block_cnt++;
    for(ll i = 0; i < a.size(); i++){
        auto [l, r] = a[i];
        R[i / N].pb(r);
        sz[i / N].pb(r - l + 1);
        req[i / N].pb(a[i]);
    }

    for(ll i = 0; i < block_cnt; i++){
        sort(R[i].begin(), R[i].end());
        sort(sz[i].begin(), sz[i].end());
    }
    lx[0] = 0; rx[block_cnt - 1] = inf;
    for(ll i = 1; i < block_cnt; i++){
        lx[i] = rx[i - 1] = req[i][0].ff;
    }

    return;
}

void solve(){

    ll n, t; cin >> n >> t;

    ll changes = 0;

    ll cur = 0;
    lx[0] = 0; rx[0] = inf;
    ll lastans = 0;

    while(n--){
        ll T; cin >> T;
        if(T == 1){
            cin >> range[++cur].ff >> range[cur].ss;
            range[cur].ff ^= (t * lastans);
            range[cur].ss ^= (t * lastans);
            if(range[cur].ff > range[cur].ss) swap(range[cur].ff, range[cur].ss);
            add(range[cur].ff, range[cur].ss);
            changes++;
        }
        if(T == 2){
            ll id; cin >> id;
            remove(range[id].ff, range[id].ss);
        }
        if(T == 3){
            lastans = query(lastans, t);
            cout << lastans << '\n';
        }
        if(changes >= N){
            changes = 0;
           // build();
        }
    }
    
   return;
}

int main() {

    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
        auto start_time = clock();
    #else
         // freopen("subsequence.in", "r", stdin);
         // freopen("subsequence.out", "w", stdout); 
         ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    #endif

    //precalc();
 
    ll T = 1, CT = 0; //cin >> T; 
 
    while(T--){
        // cout << "Case #" << ++CT << ": ";
        solve();
    }
    
    #ifdef LOCAL
        auto end_time = clock();
        cerr<< "Execution time: "<<(end_time - start_time)*(int)1e3/CLOCKS_PER_SEC<<" ms\n";
    #endif
 
    return 0;
} 

Compilation message

segments.cpp: In function 'void add(ll, ll)':
segments.cpp:57:29: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |             for(ll i = 1; i < R[block].size(); i++){
      |                           ~~^~~~~~~~~~~~~~~~~
segments.cpp: In function 'void remove(ll, ll)':
segments.cpp:68:29: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |             for(ll i = 0; i < R[block].size(); i++){
      |                           ~~^~~~~~~~~~~~~~~~~
segments.cpp:74:29: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |             for(ll i = 0; i < sz[block].size(); i++){
      |                           ~~^~~~~~~~~~~~~~~~~~
segments.cpp:79:29: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |             for(ll i = 0; i < req[block].size(); i++){
      |                           ~~^~~~~~~~~~~~~~~~~~~
segments.cpp: In function 'void build()':
segments.cpp:130:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  130 |     for(ll i = 0; i < a.size(); i++){
      |                   ~~^~~~~~~~~~
segments.cpp: In function 'void solve()':
segments.cpp:162:26: warning: operation on 'cur' may be undefined [-Wsequence-point]
  162 |             cin >> range[++cur].ff >> range[cur].ss;
      |                          ^~~~~
segments.cpp: In function 'int main()':
segments.cpp:200:15: warning: unused variable 'CT' [-Wunused-variable]
  200 |     ll T = 1, CT = 0; //cin >> T;
      |               ^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 21 ms 504 KB Output is correct
6 Correct 20 ms 612 KB Output is correct
7 Correct 8 ms 516 KB Output is correct
8 Correct 21 ms 468 KB Output is correct
9 Correct 19 ms 596 KB Output is correct
10 Correct 23 ms 628 KB Output is correct
11 Correct 16 ms 596 KB Output is correct
12 Correct 16 ms 616 KB Output is correct
13 Correct 24 ms 632 KB Output is correct
14 Correct 19 ms 468 KB Output is correct
15 Correct 2 ms 380 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 12 ms 496 KB Output is correct
18 Correct 23 ms 584 KB Output is correct
19 Correct 13 ms 508 KB Output is correct
20 Correct 13 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5051 ms 1772 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 49 ms 716 KB Output is correct
2 Correct 32 ms 724 KB Output is correct
3 Correct 83 ms 684 KB Output is correct
4 Correct 36 ms 2560 KB Output is correct
5 Execution timed out 5046 ms 3312 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 33 ms 644 KB Output is correct
2 Correct 36 ms 684 KB Output is correct
3 Correct 35 ms 636 KB Output is correct
4 Correct 41 ms 672 KB Output is correct
5 Execution timed out 5094 ms 1904 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 21 ms 504 KB Output is correct
6 Correct 20 ms 612 KB Output is correct
7 Correct 8 ms 516 KB Output is correct
8 Correct 21 ms 468 KB Output is correct
9 Correct 19 ms 596 KB Output is correct
10 Correct 23 ms 628 KB Output is correct
11 Correct 16 ms 596 KB Output is correct
12 Correct 16 ms 616 KB Output is correct
13 Correct 24 ms 632 KB Output is correct
14 Correct 19 ms 468 KB Output is correct
15 Correct 2 ms 380 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 12 ms 496 KB Output is correct
18 Correct 23 ms 584 KB Output is correct
19 Correct 13 ms 508 KB Output is correct
20 Correct 13 ms 468 KB Output is correct
21 Execution timed out 5051 ms 1772 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 21 ms 504 KB Output is correct
6 Correct 20 ms 612 KB Output is correct
7 Correct 8 ms 516 KB Output is correct
8 Correct 21 ms 468 KB Output is correct
9 Correct 19 ms 596 KB Output is correct
10 Correct 23 ms 628 KB Output is correct
11 Correct 16 ms 596 KB Output is correct
12 Correct 16 ms 616 KB Output is correct
13 Correct 24 ms 632 KB Output is correct
14 Correct 19 ms 468 KB Output is correct
15 Correct 2 ms 380 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 12 ms 496 KB Output is correct
18 Correct 23 ms 584 KB Output is correct
19 Correct 13 ms 508 KB Output is correct
20 Correct 13 ms 468 KB Output is correct
21 Execution timed out 5051 ms 1772 KB Time limit exceeded
22 Halted 0 ms 0 KB -