Submission #54412

# Submission time Handle Problem Language Result Execution time Memory
54412 2018-07-03T11:24:37 Z egorlifar Segments (IZhO18_segments) C++17
55 / 100
1014 ms 41924 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>, bool> > 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;
            l ^= pans * t;
            r ^= pans * t;
            if (l > r) {
                swap(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]}, 0});
        } 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) {
                    if (x.second) {
                        ans--;
                    } else {
                        ans++;
                    }
                }
            }
            cout << ans << '\n';
            pans = ans;
        }
    }
}       
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 10 ms 544 KB Output is correct
4 Correct 10 ms 544 KB Output is correct
5 Correct 12 ms 568 KB Output is correct
6 Correct 13 ms 568 KB Output is correct
7 Correct 11 ms 620 KB Output is correct
8 Correct 9 ms 696 KB Output is correct
9 Correct 10 ms 696 KB Output is correct
10 Correct 9 ms 840 KB Output is correct
11 Correct 23 ms 840 KB Output is correct
12 Correct 23 ms 840 KB Output is correct
13 Correct 7 ms 840 KB Output is correct
14 Correct 10 ms 840 KB Output is correct
15 Correct 12 ms 840 KB Output is correct
16 Correct 10 ms 840 KB Output is correct
17 Correct 14 ms 840 KB Output is correct
18 Correct 9 ms 840 KB Output is correct
19 Correct 13 ms 840 KB Output is correct
20 Correct 12 ms 840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 683 ms 2600 KB Output is correct
2 Correct 697 ms 2600 KB Output is correct
3 Correct 716 ms 2600 KB Output is correct
4 Correct 855 ms 2700 KB Output is correct
5 Correct 976 ms 3664 KB Output is correct
6 Correct 978 ms 3664 KB Output is correct
7 Correct 639 ms 3664 KB Output is correct
8 Correct 652 ms 3664 KB Output is correct
9 Correct 629 ms 3664 KB Output is correct
10 Correct 988 ms 3664 KB Output is correct
11 Correct 409 ms 3664 KB Output is correct
12 Correct 892 ms 3664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 196 ms 3664 KB Output is correct
2 Correct 193 ms 3664 KB Output is correct
3 Correct 223 ms 3664 KB Output is correct
4 Correct 203 ms 3664 KB Output is correct
5 Correct 977 ms 3664 KB Output is correct
6 Correct 837 ms 3664 KB Output is correct
7 Correct 950 ms 3664 KB Output is correct
8 Correct 969 ms 3664 KB Output is correct
9 Correct 966 ms 3664 KB Output is correct
10 Correct 859 ms 3664 KB Output is correct
11 Correct 315 ms 3664 KB Output is correct
12 Correct 931 ms 3664 KB Output is correct
13 Correct 847 ms 3664 KB Output is correct
14 Correct 553 ms 3664 KB Output is correct
15 Correct 515 ms 3664 KB Output is correct
16 Correct 477 ms 3664 KB Output is correct
17 Correct 801 ms 3664 KB Output is correct
18 Correct 834 ms 3664 KB Output is correct
19 Correct 844 ms 3664 KB Output is correct
20 Correct 775 ms 3664 KB Output is correct
21 Correct 338 ms 3664 KB Output is correct
22 Correct 667 ms 4188 KB Output is correct
23 Correct 797 ms 6332 KB Output is correct
24 Correct 679 ms 8348 KB Output is correct
25 Correct 201 ms 9048 KB Output is correct
26 Correct 195 ms 10972 KB Output is correct
27 Correct 200 ms 12880 KB Output is correct
28 Correct 201 ms 14704 KB Output is correct
29 Correct 823 ms 18208 KB Output is correct
30 Correct 782 ms 20216 KB Output is correct
31 Correct 1006 ms 23256 KB Output is correct
32 Correct 900 ms 24864 KB Output is correct
33 Correct 779 ms 26584 KB Output is correct
34 Correct 509 ms 27888 KB Output is correct
35 Correct 777 ms 30332 KB Output is correct
36 Correct 827 ms 32828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 193 ms 32828 KB Output is correct
2 Correct 193 ms 32828 KB Output is correct
3 Correct 182 ms 32828 KB Output is correct
4 Correct 203 ms 32828 KB Output is correct
5 Correct 805 ms 33148 KB Output is correct
6 Correct 438 ms 33148 KB Output is correct
7 Correct 886 ms 33292 KB Output is correct
8 Correct 851 ms 33292 KB Output is correct
9 Correct 576 ms 33292 KB Output is correct
10 Correct 859 ms 33292 KB Output is correct
11 Correct 368 ms 33292 KB Output is correct
12 Correct 962 ms 33516 KB Output is correct
13 Correct 796 ms 33516 KB Output is correct
14 Correct 545 ms 33516 KB Output is correct
15 Correct 973 ms 33516 KB Output is correct
16 Correct 810 ms 33516 KB Output is correct
17 Correct 668 ms 33516 KB Output is correct
18 Correct 671 ms 33516 KB Output is correct
19 Correct 694 ms 33516 KB Output is correct
20 Correct 723 ms 33516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 10 ms 544 KB Output is correct
4 Correct 10 ms 544 KB Output is correct
5 Correct 12 ms 568 KB Output is correct
6 Correct 13 ms 568 KB Output is correct
7 Correct 11 ms 620 KB Output is correct
8 Correct 9 ms 696 KB Output is correct
9 Correct 10 ms 696 KB Output is correct
10 Correct 9 ms 840 KB Output is correct
11 Correct 23 ms 840 KB Output is correct
12 Correct 23 ms 840 KB Output is correct
13 Correct 7 ms 840 KB Output is correct
14 Correct 10 ms 840 KB Output is correct
15 Correct 12 ms 840 KB Output is correct
16 Correct 10 ms 840 KB Output is correct
17 Correct 14 ms 840 KB Output is correct
18 Correct 9 ms 840 KB Output is correct
19 Correct 13 ms 840 KB Output is correct
20 Correct 12 ms 840 KB Output is correct
21 Correct 683 ms 2600 KB Output is correct
22 Correct 697 ms 2600 KB Output is correct
23 Correct 716 ms 2600 KB Output is correct
24 Correct 855 ms 2700 KB Output is correct
25 Correct 976 ms 3664 KB Output is correct
26 Correct 978 ms 3664 KB Output is correct
27 Correct 639 ms 3664 KB Output is correct
28 Correct 652 ms 3664 KB Output is correct
29 Correct 629 ms 3664 KB Output is correct
30 Correct 988 ms 3664 KB Output is correct
31 Correct 409 ms 3664 KB Output is correct
32 Correct 892 ms 3664 KB Output is correct
33 Correct 193 ms 32828 KB Output is correct
34 Correct 193 ms 32828 KB Output is correct
35 Correct 182 ms 32828 KB Output is correct
36 Correct 203 ms 32828 KB Output is correct
37 Correct 805 ms 33148 KB Output is correct
38 Correct 438 ms 33148 KB Output is correct
39 Correct 886 ms 33292 KB Output is correct
40 Correct 851 ms 33292 KB Output is correct
41 Correct 576 ms 33292 KB Output is correct
42 Correct 859 ms 33292 KB Output is correct
43 Correct 368 ms 33292 KB Output is correct
44 Correct 962 ms 33516 KB Output is correct
45 Correct 796 ms 33516 KB Output is correct
46 Correct 545 ms 33516 KB Output is correct
47 Correct 973 ms 33516 KB Output is correct
48 Correct 810 ms 33516 KB Output is correct
49 Correct 668 ms 33516 KB Output is correct
50 Correct 671 ms 33516 KB Output is correct
51 Correct 694 ms 33516 KB Output is correct
52 Correct 723 ms 33516 KB Output is correct
53 Correct 182 ms 33516 KB Output is correct
54 Correct 207 ms 33516 KB Output is correct
55 Correct 200 ms 33516 KB Output is correct
56 Correct 184 ms 33516 KB Output is correct
57 Correct 591 ms 33516 KB Output is correct
58 Correct 270 ms 33516 KB Output is correct
59 Correct 853 ms 33516 KB Output is correct
60 Correct 1010 ms 33516 KB Output is correct
61 Correct 793 ms 33516 KB Output is correct
62 Correct 964 ms 33516 KB Output is correct
63 Correct 982 ms 33712 KB Output is correct
64 Correct 1014 ms 33712 KB Output is correct
65 Correct 474 ms 33712 KB Output is correct
66 Correct 434 ms 33712 KB Output is correct
67 Correct 857 ms 33712 KB Output is correct
68 Correct 769 ms 33712 KB Output is correct
69 Correct 814 ms 33712 KB Output is correct
70 Correct 651 ms 33712 KB Output is correct
71 Correct 704 ms 33712 KB Output is correct
72 Correct 691 ms 33712 KB Output is correct
73 Correct 513 ms 33712 KB Output is correct
74 Correct 696 ms 34612 KB Output is correct
75 Correct 980 ms 38068 KB Output is correct
76 Correct 953 ms 40200 KB Output is correct
77 Correct 184 ms 40200 KB Output is correct
78 Runtime error 183 ms 41924 KB Memory limit exceeded
79 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 10 ms 544 KB Output is correct
4 Correct 10 ms 544 KB Output is correct
5 Correct 12 ms 568 KB Output is correct
6 Correct 13 ms 568 KB Output is correct
7 Correct 11 ms 620 KB Output is correct
8 Correct 9 ms 696 KB Output is correct
9 Correct 10 ms 696 KB Output is correct
10 Correct 9 ms 840 KB Output is correct
11 Correct 23 ms 840 KB Output is correct
12 Correct 23 ms 840 KB Output is correct
13 Correct 7 ms 840 KB Output is correct
14 Correct 10 ms 840 KB Output is correct
15 Correct 12 ms 840 KB Output is correct
16 Correct 10 ms 840 KB Output is correct
17 Correct 14 ms 840 KB Output is correct
18 Correct 9 ms 840 KB Output is correct
19 Correct 13 ms 840 KB Output is correct
20 Correct 12 ms 840 KB Output is correct
21 Correct 683 ms 2600 KB Output is correct
22 Correct 697 ms 2600 KB Output is correct
23 Correct 716 ms 2600 KB Output is correct
24 Correct 855 ms 2700 KB Output is correct
25 Correct 976 ms 3664 KB Output is correct
26 Correct 978 ms 3664 KB Output is correct
27 Correct 639 ms 3664 KB Output is correct
28 Correct 652 ms 3664 KB Output is correct
29 Correct 629 ms 3664 KB Output is correct
30 Correct 988 ms 3664 KB Output is correct
31 Correct 409 ms 3664 KB Output is correct
32 Correct 892 ms 3664 KB Output is correct
33 Correct 196 ms 3664 KB Output is correct
34 Correct 193 ms 3664 KB Output is correct
35 Correct 223 ms 3664 KB Output is correct
36 Correct 203 ms 3664 KB Output is correct
37 Correct 977 ms 3664 KB Output is correct
38 Correct 837 ms 3664 KB Output is correct
39 Correct 950 ms 3664 KB Output is correct
40 Correct 969 ms 3664 KB Output is correct
41 Correct 966 ms 3664 KB Output is correct
42 Correct 859 ms 3664 KB Output is correct
43 Correct 315 ms 3664 KB Output is correct
44 Correct 931 ms 3664 KB Output is correct
45 Correct 847 ms 3664 KB Output is correct
46 Correct 553 ms 3664 KB Output is correct
47 Correct 515 ms 3664 KB Output is correct
48 Correct 477 ms 3664 KB Output is correct
49 Correct 801 ms 3664 KB Output is correct
50 Correct 834 ms 3664 KB Output is correct
51 Correct 844 ms 3664 KB Output is correct
52 Correct 775 ms 3664 KB Output is correct
53 Correct 338 ms 3664 KB Output is correct
54 Correct 667 ms 4188 KB Output is correct
55 Correct 797 ms 6332 KB Output is correct
56 Correct 679 ms 8348 KB Output is correct
57 Correct 201 ms 9048 KB Output is correct
58 Correct 195 ms 10972 KB Output is correct
59 Correct 200 ms 12880 KB Output is correct
60 Correct 201 ms 14704 KB Output is correct
61 Correct 823 ms 18208 KB Output is correct
62 Correct 782 ms 20216 KB Output is correct
63 Correct 1006 ms 23256 KB Output is correct
64 Correct 900 ms 24864 KB Output is correct
65 Correct 779 ms 26584 KB Output is correct
66 Correct 509 ms 27888 KB Output is correct
67 Correct 777 ms 30332 KB Output is correct
68 Correct 827 ms 32828 KB Output is correct
69 Correct 193 ms 32828 KB Output is correct
70 Correct 193 ms 32828 KB Output is correct
71 Correct 182 ms 32828 KB Output is correct
72 Correct 203 ms 32828 KB Output is correct
73 Correct 805 ms 33148 KB Output is correct
74 Correct 438 ms 33148 KB Output is correct
75 Correct 886 ms 33292 KB Output is correct
76 Correct 851 ms 33292 KB Output is correct
77 Correct 576 ms 33292 KB Output is correct
78 Correct 859 ms 33292 KB Output is correct
79 Correct 368 ms 33292 KB Output is correct
80 Correct 962 ms 33516 KB Output is correct
81 Correct 796 ms 33516 KB Output is correct
82 Correct 545 ms 33516 KB Output is correct
83 Correct 973 ms 33516 KB Output is correct
84 Correct 810 ms 33516 KB Output is correct
85 Correct 668 ms 33516 KB Output is correct
86 Correct 671 ms 33516 KB Output is correct
87 Correct 694 ms 33516 KB Output is correct
88 Correct 723 ms 33516 KB Output is correct
89 Correct 182 ms 33516 KB Output is correct
90 Correct 207 ms 33516 KB Output is correct
91 Correct 200 ms 33516 KB Output is correct
92 Correct 184 ms 33516 KB Output is correct
93 Correct 591 ms 33516 KB Output is correct
94 Correct 270 ms 33516 KB Output is correct
95 Correct 853 ms 33516 KB Output is correct
96 Correct 1010 ms 33516 KB Output is correct
97 Correct 793 ms 33516 KB Output is correct
98 Correct 964 ms 33516 KB Output is correct
99 Correct 982 ms 33712 KB Output is correct
100 Correct 1014 ms 33712 KB Output is correct
101 Correct 474 ms 33712 KB Output is correct
102 Correct 434 ms 33712 KB Output is correct
103 Correct 857 ms 33712 KB Output is correct
104 Correct 769 ms 33712 KB Output is correct
105 Correct 814 ms 33712 KB Output is correct
106 Correct 651 ms 33712 KB Output is correct
107 Correct 704 ms 33712 KB Output is correct
108 Correct 691 ms 33712 KB Output is correct
109 Correct 513 ms 33712 KB Output is correct
110 Correct 696 ms 34612 KB Output is correct
111 Correct 980 ms 38068 KB Output is correct
112 Correct 953 ms 40200 KB Output is correct
113 Correct 184 ms 40200 KB Output is correct
114 Runtime error 183 ms 41924 KB Memory limit exceeded
115 Halted 0 ms 0 KB -