Submission #54411

# Submission time Handle Problem Language Result Execution time Memory
54411 2018-07-03T11:20:36 Z egorlifar Segments (IZhO18_segments) C++17
39 / 100
1014 ms 3600 KB
/*
ЗАПУСКАЕМ 
░ГУСЯ░▄▀▀▀▄░РАБОТЯГУ░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░ 
 */
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <iomanip>
#include <deque>
    
     
using namespace std;
template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; } 
template<typename T, typename U> inline ostream &operator<< (ostream &_out, const pair<T, U> &_p) { _out << _p.first << ' ' << _p.second; return _out; }
template<typename T, typename U> inline istream &operator>> (istream &_in, pair<T, U> &_p) { _in >> _p.first >> _p.second; return _in; }
template<typename T> inline ostream &operator<< (ostream &_out, const vector<T> &_v) { if (_v.empty()) { return _out; } _out << _v.front(); for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline istream &operator>> (istream &_in, vector<T> &_v) { for (auto &_i : _v) { _in >> _i; } return _in; }
template<typename T> inline ostream &operator<< (ostream &_out, const set<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline ostream &operator<< (ostream &_out, const multiset<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline ostream &operator<< (ostream &_out, const unordered_set<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline ostream &operator<< (ostream &_out, const unordered_multiset<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T, typename U> inline ostream &operator<< (ostream &_out, const map<T, U> &_m) { if (_m.empty()) { return _out; } _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')'; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) { _out << ", (" << _it->first << ": " << _it->second << ')'; } return _out; }
template<typename T, typename U> inline ostream &operator<< (ostream &_out, const unordered_map<T, U> &_m) { if (_m.empty()) { return _out; } _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')'; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) { _out << ", (" << _it->first << ": " << _it->second << ')'; } return _out; }
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define left left228
#define right right228
#define next next228
#define rank rank228
#define prev prev228
#define y1 y1228                                                         
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define files(FILENAME) read(FILENAME), write(FILENAME)
#define pb push_back
#define x first
#define y second
const string FILENAME = "input";
const int MAXN = 200228;
const int MAGIC = 1500;

//12:00
//17:00
int n, t;
int id = 0;
bool alive[MAXN];
int L[MAXN], R[MAXN];
int ids[MAXN];
int li[MAXN], ri[MAXN];
int lsz[MAXN], rsz[MAXN];
int cntin;


bool comp(const int &a, const int &b) {
    return R[a] - L[a] + 1 < R[b] - L[b] + 1;
}


int cntsmall(int l, int r, int k) {
    while (l != r){
        int mid = (l + r) >> 1;
        if (rsz[mid] - lsz[mid] + 1 >= k) {
            r = mid;
        } else {
            l = mid + 1;
        }
    }
    if (rsz[l] - lsz[l] + 1 < k) {
        return l + 1;
    }
    return l;
}
 

int getl(int pos, int k) {
    int res = 0;
    int border = (pos / MAGIC + 1) * MAGIC;
    for (int i = pos; i < min(border, cntin); i++) {
        if (rsz[i] < k) {
            res--;
        }
    }
    for (int i = border; i < cntin; i += MAGIC){
        int lb = i, rb = min(i + MAGIC, cntin);
        int val = lower_bound(ri + lb, ri + rb, k) - ri - lb;
        res -= val;
    }
    return res;
}

 
int getr(int pos, int k) {
    int res = 0;
    int border = (pos / MAGIC + 1) * MAGIC;
    for (int i = pos; i < min(border, cntin); i++) {
        if (lsz[i] > k) {
            res--;
        }
    }
    for (int i = border; i < cntin; i += MAGIC) {
        int lb  = i, rb = min(i + MAGIC, cntin);
        int val = rb - (upper_bound(li + lb, li + rb, k) - li);
        res -= val;
    }
    return res;
}



int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//read(FILENAME);
    cin >> n >> t;
    int cnt = 0;
    vector<pair<pair<int, int>, int> > st;
    int pans = 0;
    for (int it = 0; it < n; it++) {
        if (sz(st) >= MAGIC) {
            cntin = 0;
            st.clear();
            for (int i = 1; i < MAXN; i++) {
                if (alive[i]) {
                    ids[cntin] = i;
                    cntin++;
                }
            }
            sort(ids, ids + cntin, comp);
            for (int i = 0; i < cntin; i++) {
                li[i] = lsz[i] = L[ids[i]];
            }
            for (int i = 0; i < cntin; i++) {
                ri[i] = rsz[i] = R[ids[i]];
            }
            for (int i = 0; i < cntin; i += MAGIC){
                int lb = i, rb = min(i + MAGIC, cntin);
                sort(li + lb, li + rb);
                sort(ri + lb, ri + rb);
            }
        }
        int type;
        cin >> type;
        if (type == 1) {
            int l, r;
            cin >> l >> r;
            id++;
            cnt++;
            alive[id] = true;
            L[id] = l;
            R[id] = r;
            st.pb({{l, r}, 1});
        } else if (type == 2) {
            int id1;
            cin >> id1;
            cnt--;
            alive[id1] = false;
            st.pb({{L[id1], R[id1]}, -1});
        } else if (type == 3) {
            int l, r, k;
            cin >> l >> r >> k;
            l ^= pans * t;
            r ^= pans * t;
            if (l > r) {
                swap(l, r);
            }
            if (r - l + 1 < k) {
                cout << 0 << '\n';
                pans = 0;
                continue;
            }
            int ans = cnt;
            if (cntin) {
                int pos = cntsmall(0, cntin - 1, k);
                ans -= pos;
                ans += getl(pos, l + k - 1);
                ans += getr(pos, r - k + 1);
            }
            for (auto x: st) {
                int tl = max(x.first.first, l);
                int tr = min(x.first.second, r);
                if (tr - tl + 1 < k) {
                    ans -= x.second;
                }
            }
            cout << ans << '\n';
            pans = ans;
        }
    }
}       
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 444 KB Output is correct
3 Correct 9 ms 544 KB Output is correct
4 Correct 8 ms 692 KB Output is correct
5 Correct 10 ms 692 KB Output is correct
6 Correct 11 ms 692 KB Output is correct
7 Correct 11 ms 692 KB Output is correct
8 Correct 8 ms 692 KB Output is correct
9 Correct 9 ms 692 KB Output is correct
10 Correct 7 ms 692 KB Output is correct
11 Correct 17 ms 712 KB Output is correct
12 Correct 17 ms 712 KB Output is correct
13 Correct 7 ms 788 KB Output is correct
14 Correct 9 ms 788 KB Output is correct
15 Correct 8 ms 788 KB Output is correct
16 Correct 8 ms 788 KB Output is correct
17 Correct 9 ms 788 KB Output is correct
18 Correct 9 ms 788 KB Output is correct
19 Correct 10 ms 856 KB Output is correct
20 Correct 10 ms 856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 629 ms 2620 KB Output is correct
2 Correct 665 ms 2620 KB Output is correct
3 Correct 602 ms 2620 KB Output is correct
4 Correct 689 ms 2644 KB Output is correct
5 Correct 941 ms 3428 KB Output is correct
6 Correct 969 ms 3512 KB Output is correct
7 Correct 618 ms 3512 KB Output is correct
8 Correct 590 ms 3512 KB Output is correct
9 Correct 606 ms 3512 KB Output is correct
10 Correct 704 ms 3512 KB Output is correct
11 Correct 389 ms 3512 KB Output is correct
12 Correct 850 ms 3512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 142 ms 3512 KB Output is correct
2 Correct 168 ms 3512 KB Output is correct
3 Correct 148 ms 3512 KB Output is correct
4 Correct 155 ms 3512 KB Output is correct
5 Correct 896 ms 3512 KB Output is correct
6 Correct 771 ms 3512 KB Output is correct
7 Correct 861 ms 3512 KB Output is correct
8 Correct 961 ms 3592 KB Output is correct
9 Correct 966 ms 3592 KB Output is correct
10 Correct 849 ms 3592 KB Output is correct
11 Correct 251 ms 3592 KB Output is correct
12 Correct 855 ms 3592 KB Output is correct
13 Correct 785 ms 3592 KB Output is correct
14 Correct 510 ms 3592 KB Output is correct
15 Correct 505 ms 3592 KB Output is correct
16 Correct 379 ms 3592 KB Output is correct
17 Correct 741 ms 3592 KB Output is correct
18 Correct 724 ms 3592 KB Output is correct
19 Correct 701 ms 3592 KB Output is correct
20 Correct 711 ms 3592 KB Output is correct
21 Incorrect 320 ms 3592 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 131 ms 3592 KB Output is correct
2 Correct 171 ms 3592 KB Output is correct
3 Correct 139 ms 3592 KB Output is correct
4 Correct 137 ms 3592 KB Output is correct
5 Correct 797 ms 3592 KB Output is correct
6 Correct 359 ms 3592 KB Output is correct
7 Correct 931 ms 3592 KB Output is correct
8 Correct 702 ms 3592 KB Output is correct
9 Correct 564 ms 3592 KB Output is correct
10 Correct 846 ms 3592 KB Output is correct
11 Correct 313 ms 3592 KB Output is correct
12 Correct 957 ms 3600 KB Output is correct
13 Correct 744 ms 3600 KB Output is correct
14 Correct 509 ms 3600 KB Output is correct
15 Correct 942 ms 3600 KB Output is correct
16 Correct 786 ms 3600 KB Output is correct
17 Correct 596 ms 3600 KB Output is correct
18 Correct 597 ms 3600 KB Output is correct
19 Correct 591 ms 3600 KB Output is correct
20 Correct 626 ms 3600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 444 KB Output is correct
3 Correct 9 ms 544 KB Output is correct
4 Correct 8 ms 692 KB Output is correct
5 Correct 10 ms 692 KB Output is correct
6 Correct 11 ms 692 KB Output is correct
7 Correct 11 ms 692 KB Output is correct
8 Correct 8 ms 692 KB Output is correct
9 Correct 9 ms 692 KB Output is correct
10 Correct 7 ms 692 KB Output is correct
11 Correct 17 ms 712 KB Output is correct
12 Correct 17 ms 712 KB Output is correct
13 Correct 7 ms 788 KB Output is correct
14 Correct 9 ms 788 KB Output is correct
15 Correct 8 ms 788 KB Output is correct
16 Correct 8 ms 788 KB Output is correct
17 Correct 9 ms 788 KB Output is correct
18 Correct 9 ms 788 KB Output is correct
19 Correct 10 ms 856 KB Output is correct
20 Correct 10 ms 856 KB Output is correct
21 Correct 629 ms 2620 KB Output is correct
22 Correct 665 ms 2620 KB Output is correct
23 Correct 602 ms 2620 KB Output is correct
24 Correct 689 ms 2644 KB Output is correct
25 Correct 941 ms 3428 KB Output is correct
26 Correct 969 ms 3512 KB Output is correct
27 Correct 618 ms 3512 KB Output is correct
28 Correct 590 ms 3512 KB Output is correct
29 Correct 606 ms 3512 KB Output is correct
30 Correct 704 ms 3512 KB Output is correct
31 Correct 389 ms 3512 KB Output is correct
32 Correct 850 ms 3512 KB Output is correct
33 Correct 131 ms 3592 KB Output is correct
34 Correct 171 ms 3592 KB Output is correct
35 Correct 139 ms 3592 KB Output is correct
36 Correct 137 ms 3592 KB Output is correct
37 Correct 797 ms 3592 KB Output is correct
38 Correct 359 ms 3592 KB Output is correct
39 Correct 931 ms 3592 KB Output is correct
40 Correct 702 ms 3592 KB Output is correct
41 Correct 564 ms 3592 KB Output is correct
42 Correct 846 ms 3592 KB Output is correct
43 Correct 313 ms 3592 KB Output is correct
44 Correct 957 ms 3600 KB Output is correct
45 Correct 744 ms 3600 KB Output is correct
46 Correct 509 ms 3600 KB Output is correct
47 Correct 942 ms 3600 KB Output is correct
48 Correct 786 ms 3600 KB Output is correct
49 Correct 596 ms 3600 KB Output is correct
50 Correct 597 ms 3600 KB Output is correct
51 Correct 591 ms 3600 KB Output is correct
52 Correct 626 ms 3600 KB Output is correct
53 Correct 147 ms 3600 KB Output is correct
54 Correct 152 ms 3600 KB Output is correct
55 Correct 142 ms 3600 KB Output is correct
56 Correct 139 ms 3600 KB Output is correct
57 Correct 483 ms 3600 KB Output is correct
58 Correct 286 ms 3600 KB Output is correct
59 Correct 769 ms 3600 KB Output is correct
60 Correct 676 ms 3600 KB Output is correct
61 Correct 884 ms 3600 KB Output is correct
62 Correct 1014 ms 3600 KB Output is correct
63 Correct 983 ms 3600 KB Output is correct
64 Correct 915 ms 3600 KB Output is correct
65 Correct 382 ms 3600 KB Output is correct
66 Correct 342 ms 3600 KB Output is correct
67 Correct 782 ms 3600 KB Output is correct
68 Correct 681 ms 3600 KB Output is correct
69 Correct 589 ms 3600 KB Output is correct
70 Correct 592 ms 3600 KB Output is correct
71 Correct 621 ms 3600 KB Output is correct
72 Correct 666 ms 3600 KB Output is correct
73 Incorrect 444 ms 3600 KB Output isn't correct
74 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 444 KB Output is correct
3 Correct 9 ms 544 KB Output is correct
4 Correct 8 ms 692 KB Output is correct
5 Correct 10 ms 692 KB Output is correct
6 Correct 11 ms 692 KB Output is correct
7 Correct 11 ms 692 KB Output is correct
8 Correct 8 ms 692 KB Output is correct
9 Correct 9 ms 692 KB Output is correct
10 Correct 7 ms 692 KB Output is correct
11 Correct 17 ms 712 KB Output is correct
12 Correct 17 ms 712 KB Output is correct
13 Correct 7 ms 788 KB Output is correct
14 Correct 9 ms 788 KB Output is correct
15 Correct 8 ms 788 KB Output is correct
16 Correct 8 ms 788 KB Output is correct
17 Correct 9 ms 788 KB Output is correct
18 Correct 9 ms 788 KB Output is correct
19 Correct 10 ms 856 KB Output is correct
20 Correct 10 ms 856 KB Output is correct
21 Correct 629 ms 2620 KB Output is correct
22 Correct 665 ms 2620 KB Output is correct
23 Correct 602 ms 2620 KB Output is correct
24 Correct 689 ms 2644 KB Output is correct
25 Correct 941 ms 3428 KB Output is correct
26 Correct 969 ms 3512 KB Output is correct
27 Correct 618 ms 3512 KB Output is correct
28 Correct 590 ms 3512 KB Output is correct
29 Correct 606 ms 3512 KB Output is correct
30 Correct 704 ms 3512 KB Output is correct
31 Correct 389 ms 3512 KB Output is correct
32 Correct 850 ms 3512 KB Output is correct
33 Correct 142 ms 3512 KB Output is correct
34 Correct 168 ms 3512 KB Output is correct
35 Correct 148 ms 3512 KB Output is correct
36 Correct 155 ms 3512 KB Output is correct
37 Correct 896 ms 3512 KB Output is correct
38 Correct 771 ms 3512 KB Output is correct
39 Correct 861 ms 3512 KB Output is correct
40 Correct 961 ms 3592 KB Output is correct
41 Correct 966 ms 3592 KB Output is correct
42 Correct 849 ms 3592 KB Output is correct
43 Correct 251 ms 3592 KB Output is correct
44 Correct 855 ms 3592 KB Output is correct
45 Correct 785 ms 3592 KB Output is correct
46 Correct 510 ms 3592 KB Output is correct
47 Correct 505 ms 3592 KB Output is correct
48 Correct 379 ms 3592 KB Output is correct
49 Correct 741 ms 3592 KB Output is correct
50 Correct 724 ms 3592 KB Output is correct
51 Correct 701 ms 3592 KB Output is correct
52 Correct 711 ms 3592 KB Output is correct
53 Incorrect 320 ms 3592 KB Output isn't correct
54 Halted 0 ms 0 KB -