/*
ЗАПУСКАЕМ
░ГУСЯ░▄▀▀▀▄░РАБОТЯГУ░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░
*/
#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 id;
cin >> id;
cnt--;
alive[id] = false;
st.pb({{L[id], R[id]}, -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;
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
480 KB |
Output is correct |
3 |
Correct |
10 ms |
552 KB |
Output is correct |
4 |
Correct |
8 ms |
788 KB |
Output is correct |
5 |
Correct |
10 ms |
1100 KB |
Output is correct |
6 |
Correct |
11 ms |
1180 KB |
Output is correct |
7 |
Correct |
9 ms |
1368 KB |
Output is correct |
8 |
Correct |
8 ms |
1512 KB |
Output is correct |
9 |
Correct |
9 ms |
1620 KB |
Output is correct |
10 |
Correct |
7 ms |
1728 KB |
Output is correct |
11 |
Correct |
17 ms |
1856 KB |
Output is correct |
12 |
Correct |
18 ms |
2048 KB |
Output is correct |
13 |
Correct |
9 ms |
2160 KB |
Output is correct |
14 |
Correct |
10 ms |
2196 KB |
Output is correct |
15 |
Correct |
8 ms |
2252 KB |
Output is correct |
16 |
Correct |
8 ms |
2356 KB |
Output is correct |
17 |
Correct |
9 ms |
2496 KB |
Output is correct |
18 |
Correct |
8 ms |
2720 KB |
Output is correct |
19 |
Correct |
10 ms |
2808 KB |
Output is correct |
20 |
Correct |
10 ms |
2912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
587 ms |
6056 KB |
Output is correct |
2 |
Correct |
594 ms |
8588 KB |
Output is correct |
3 |
Correct |
592 ms |
11280 KB |
Output is correct |
4 |
Correct |
685 ms |
14088 KB |
Output is correct |
5 |
Correct |
919 ms |
17140 KB |
Output is correct |
6 |
Correct |
980 ms |
19568 KB |
Output is correct |
7 |
Correct |
638 ms |
21020 KB |
Output is correct |
8 |
Correct |
599 ms |
23768 KB |
Output is correct |
9 |
Correct |
575 ms |
26496 KB |
Output is correct |
10 |
Correct |
689 ms |
28660 KB |
Output is correct |
11 |
Correct |
379 ms |
31752 KB |
Output is correct |
12 |
Correct |
782 ms |
35412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
132 ms |
35412 KB |
Output is correct |
2 |
Correct |
125 ms |
35412 KB |
Output is correct |
3 |
Correct |
146 ms |
35412 KB |
Output is correct |
4 |
Correct |
129 ms |
35412 KB |
Output is correct |
5 |
Correct |
840 ms |
35412 KB |
Output is correct |
6 |
Correct |
788 ms |
35412 KB |
Output is correct |
7 |
Correct |
858 ms |
35412 KB |
Output is correct |
8 |
Correct |
1008 ms |
35816 KB |
Output is correct |
9 |
Correct |
972 ms |
35828 KB |
Output is correct |
10 |
Correct |
854 ms |
35828 KB |
Output is correct |
11 |
Correct |
260 ms |
35828 KB |
Output is correct |
12 |
Correct |
847 ms |
35828 KB |
Output is correct |
13 |
Correct |
757 ms |
35828 KB |
Output is correct |
14 |
Correct |
522 ms |
35828 KB |
Output is correct |
15 |
Correct |
462 ms |
35828 KB |
Output is correct |
16 |
Correct |
400 ms |
35828 KB |
Output is correct |
17 |
Correct |
715 ms |
35828 KB |
Output is correct |
18 |
Correct |
718 ms |
35828 KB |
Output is correct |
19 |
Correct |
769 ms |
37168 KB |
Output is correct |
20 |
Correct |
731 ms |
39600 KB |
Output is correct |
21 |
Incorrect |
270 ms |
40420 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
134 ms |
40420 KB |
Output is correct |
2 |
Runtime error |
132 ms |
41984 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
480 KB |
Output is correct |
3 |
Correct |
10 ms |
552 KB |
Output is correct |
4 |
Correct |
8 ms |
788 KB |
Output is correct |
5 |
Correct |
10 ms |
1100 KB |
Output is correct |
6 |
Correct |
11 ms |
1180 KB |
Output is correct |
7 |
Correct |
9 ms |
1368 KB |
Output is correct |
8 |
Correct |
8 ms |
1512 KB |
Output is correct |
9 |
Correct |
9 ms |
1620 KB |
Output is correct |
10 |
Correct |
7 ms |
1728 KB |
Output is correct |
11 |
Correct |
17 ms |
1856 KB |
Output is correct |
12 |
Correct |
18 ms |
2048 KB |
Output is correct |
13 |
Correct |
9 ms |
2160 KB |
Output is correct |
14 |
Correct |
10 ms |
2196 KB |
Output is correct |
15 |
Correct |
8 ms |
2252 KB |
Output is correct |
16 |
Correct |
8 ms |
2356 KB |
Output is correct |
17 |
Correct |
9 ms |
2496 KB |
Output is correct |
18 |
Correct |
8 ms |
2720 KB |
Output is correct |
19 |
Correct |
10 ms |
2808 KB |
Output is correct |
20 |
Correct |
10 ms |
2912 KB |
Output is correct |
21 |
Correct |
587 ms |
6056 KB |
Output is correct |
22 |
Correct |
594 ms |
8588 KB |
Output is correct |
23 |
Correct |
592 ms |
11280 KB |
Output is correct |
24 |
Correct |
685 ms |
14088 KB |
Output is correct |
25 |
Correct |
919 ms |
17140 KB |
Output is correct |
26 |
Correct |
980 ms |
19568 KB |
Output is correct |
27 |
Correct |
638 ms |
21020 KB |
Output is correct |
28 |
Correct |
599 ms |
23768 KB |
Output is correct |
29 |
Correct |
575 ms |
26496 KB |
Output is correct |
30 |
Correct |
689 ms |
28660 KB |
Output is correct |
31 |
Correct |
379 ms |
31752 KB |
Output is correct |
32 |
Correct |
782 ms |
35412 KB |
Output is correct |
33 |
Correct |
134 ms |
40420 KB |
Output is correct |
34 |
Runtime error |
132 ms |
41984 KB |
Memory limit exceeded |
35 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
480 KB |
Output is correct |
3 |
Correct |
10 ms |
552 KB |
Output is correct |
4 |
Correct |
8 ms |
788 KB |
Output is correct |
5 |
Correct |
10 ms |
1100 KB |
Output is correct |
6 |
Correct |
11 ms |
1180 KB |
Output is correct |
7 |
Correct |
9 ms |
1368 KB |
Output is correct |
8 |
Correct |
8 ms |
1512 KB |
Output is correct |
9 |
Correct |
9 ms |
1620 KB |
Output is correct |
10 |
Correct |
7 ms |
1728 KB |
Output is correct |
11 |
Correct |
17 ms |
1856 KB |
Output is correct |
12 |
Correct |
18 ms |
2048 KB |
Output is correct |
13 |
Correct |
9 ms |
2160 KB |
Output is correct |
14 |
Correct |
10 ms |
2196 KB |
Output is correct |
15 |
Correct |
8 ms |
2252 KB |
Output is correct |
16 |
Correct |
8 ms |
2356 KB |
Output is correct |
17 |
Correct |
9 ms |
2496 KB |
Output is correct |
18 |
Correct |
8 ms |
2720 KB |
Output is correct |
19 |
Correct |
10 ms |
2808 KB |
Output is correct |
20 |
Correct |
10 ms |
2912 KB |
Output is correct |
21 |
Correct |
587 ms |
6056 KB |
Output is correct |
22 |
Correct |
594 ms |
8588 KB |
Output is correct |
23 |
Correct |
592 ms |
11280 KB |
Output is correct |
24 |
Correct |
685 ms |
14088 KB |
Output is correct |
25 |
Correct |
919 ms |
17140 KB |
Output is correct |
26 |
Correct |
980 ms |
19568 KB |
Output is correct |
27 |
Correct |
638 ms |
21020 KB |
Output is correct |
28 |
Correct |
599 ms |
23768 KB |
Output is correct |
29 |
Correct |
575 ms |
26496 KB |
Output is correct |
30 |
Correct |
689 ms |
28660 KB |
Output is correct |
31 |
Correct |
379 ms |
31752 KB |
Output is correct |
32 |
Correct |
782 ms |
35412 KB |
Output is correct |
33 |
Correct |
132 ms |
35412 KB |
Output is correct |
34 |
Correct |
125 ms |
35412 KB |
Output is correct |
35 |
Correct |
146 ms |
35412 KB |
Output is correct |
36 |
Correct |
129 ms |
35412 KB |
Output is correct |
37 |
Correct |
840 ms |
35412 KB |
Output is correct |
38 |
Correct |
788 ms |
35412 KB |
Output is correct |
39 |
Correct |
858 ms |
35412 KB |
Output is correct |
40 |
Correct |
1008 ms |
35816 KB |
Output is correct |
41 |
Correct |
972 ms |
35828 KB |
Output is correct |
42 |
Correct |
854 ms |
35828 KB |
Output is correct |
43 |
Correct |
260 ms |
35828 KB |
Output is correct |
44 |
Correct |
847 ms |
35828 KB |
Output is correct |
45 |
Correct |
757 ms |
35828 KB |
Output is correct |
46 |
Correct |
522 ms |
35828 KB |
Output is correct |
47 |
Correct |
462 ms |
35828 KB |
Output is correct |
48 |
Correct |
400 ms |
35828 KB |
Output is correct |
49 |
Correct |
715 ms |
35828 KB |
Output is correct |
50 |
Correct |
718 ms |
35828 KB |
Output is correct |
51 |
Correct |
769 ms |
37168 KB |
Output is correct |
52 |
Correct |
731 ms |
39600 KB |
Output is correct |
53 |
Incorrect |
270 ms |
40420 KB |
Output isn't correct |
54 |
Halted |
0 ms |
0 KB |
- |