답안 #42815

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
42815 2018-03-04T13:52:06 Z minhtung0404 Segments (IZhO18_segments) C++14
7 / 100
5000 ms 4212 KB
//https://oj.uz/problem/view/IZhO18_segments

#include<bits/stdc++.h>
const int N = 2e5 + 5;
const int MAGIC = 1001;
using namespace std;

struct segment{
    int l, r, id;
};

vector <segment> mv;
int n, t, L[N], R[N], ans, cnt, cur;
int l_sort[N], r_sort[N], l_nosort[N], r_nosort[N], p[N], num;
bool ck[N];

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

void get_L(int pos, int k){
    int Max = (pos / MAGIC + 1) * MAGIC;
    for (int i = pos; i < min(Max, cnt); i++) if (r_nosort[pos] < k) ans--;
    for (int i = Max; i < cnt; i += MAGIC){
        int x = i, y = min(i + MAGIC, cnt);
        int val = lower_bound(r_sort+x, r_sort+y, k) - r_sort - x;
        ans -= val;
    }
}

void get_R(int pos, int k){
    int Max = (pos / MAGIC + 1) * MAGIC;
    for (int i = pos; i < min(Max, cnt); i++) if (l_nosort[pos] > k) ans--;
    for (int i = Max; i < cnt; i += MAGIC){
        int x = i, y = min(i + MAGIC, cnt);
        int val = y - (upper_bound(l_sort+x, l_sort+y, k) - l_sort);
        ans -= val;
    }
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> t;
    while (n--){
//        if (mv.size() == MAGIC){
//            cnt = 0; mv.clear();
//            for (int i = 1; i < N; i++) if (ck[i]) p[cnt++] = i;
//            sort(p, p+cnt, [](int x, int y){return (R[x] - L[x]) < (R[y] - L[y]);});
//            for (int i = 0; i < cnt; i++) l_sort[i] = l_nosort[i] = L[p[i]];
//            for (int i = 0; i < cnt; i++) r_sort[i] = r_nosort[i] = R[p[i]];
//            for (int i = 0; i < cnt; i += MAGIC){
//                int x = i, y = min(i + MAGIC, cnt);
//                sort(l_sort+x, l_sort+y);
//                sort(r_sort+x, r_sort+y);
//            }
//        }
        int type, l, r, id, k;
        cin >> type;
        if (type == 1){
            num++; id = ++cur;
            cin >> l >> r;
            l ^= (t * ans); r ^= (t * ans); if (r < l) swap(l, r);
            ck[id] = true;
            L[id] = l; R[id] = r;
            mv.push_back({l, r, 1});
        }
        if (type == 2){
            num--;
            cin >> id;
            ck[id] = false;
            mv.push_back({L[id], R[id], -1});
        }
        if (type == 3){
            cin >> l >> r >> k;
            l ^= (t * ans); r ^= (t * ans); if (r < l) swap(l, r);
            if (r - l + 1 < k){
                ans = 0; cout << ans << "\n";
                continue;
            }
            ans = num;
//            if (cnt > 0){
//                int pos = bsearch(0, cnt-1, k);
//                ans -= pos;
//                get_L(pos, l + k - 1);
//                get_R(pos, r - k + 1);
//            }
            for (int i = 0; i < mv.size(); i++){
                int x = max(mv[i].l, l), y = min(mv[i].r, r);
                if (y - x + 1 < k) ans -= mv[i].id;
            }
            cout << ans << "\n";
        }
    }
}
/*
*/

Compilation message

segments.cpp: In function 'int main()':
segments.cpp:93:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int i = 0; i < mv.size(); i++){
                               ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 376 KB Output is correct
2 Correct 2 ms 472 KB Output is correct
3 Correct 16 ms 552 KB Output is correct
4 Correct 17 ms 844 KB Output is correct
5 Correct 21 ms 964 KB Output is correct
6 Correct 26 ms 972 KB Output is correct
7 Correct 18 ms 1164 KB Output is correct
8 Correct 16 ms 1288 KB Output is correct
9 Correct 18 ms 1412 KB Output is correct
10 Correct 11 ms 1648 KB Output is correct
11 Correct 38 ms 1700 KB Output is correct
12 Correct 39 ms 1840 KB Output is correct
13 Correct 8 ms 1976 KB Output is correct
14 Correct 16 ms 2108 KB Output is correct
15 Correct 16 ms 2108 KB Output is correct
16 Correct 17 ms 2320 KB Output is correct
17 Correct 18 ms 2424 KB Output is correct
18 Correct 10 ms 2532 KB Output is correct
19 Correct 20 ms 2644 KB Output is correct
20 Correct 23 ms 2736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5014 ms 4212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5001 ms 4212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5011 ms 4212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 376 KB Output is correct
2 Correct 2 ms 472 KB Output is correct
3 Correct 16 ms 552 KB Output is correct
4 Correct 17 ms 844 KB Output is correct
5 Correct 21 ms 964 KB Output is correct
6 Correct 26 ms 972 KB Output is correct
7 Correct 18 ms 1164 KB Output is correct
8 Correct 16 ms 1288 KB Output is correct
9 Correct 18 ms 1412 KB Output is correct
10 Correct 11 ms 1648 KB Output is correct
11 Correct 38 ms 1700 KB Output is correct
12 Correct 39 ms 1840 KB Output is correct
13 Correct 8 ms 1976 KB Output is correct
14 Correct 16 ms 2108 KB Output is correct
15 Correct 16 ms 2108 KB Output is correct
16 Correct 17 ms 2320 KB Output is correct
17 Correct 18 ms 2424 KB Output is correct
18 Correct 10 ms 2532 KB Output is correct
19 Correct 20 ms 2644 KB Output is correct
20 Correct 23 ms 2736 KB Output is correct
21 Execution timed out 5014 ms 4212 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 376 KB Output is correct
2 Correct 2 ms 472 KB Output is correct
3 Correct 16 ms 552 KB Output is correct
4 Correct 17 ms 844 KB Output is correct
5 Correct 21 ms 964 KB Output is correct
6 Correct 26 ms 972 KB Output is correct
7 Correct 18 ms 1164 KB Output is correct
8 Correct 16 ms 1288 KB Output is correct
9 Correct 18 ms 1412 KB Output is correct
10 Correct 11 ms 1648 KB Output is correct
11 Correct 38 ms 1700 KB Output is correct
12 Correct 39 ms 1840 KB Output is correct
13 Correct 8 ms 1976 KB Output is correct
14 Correct 16 ms 2108 KB Output is correct
15 Correct 16 ms 2108 KB Output is correct
16 Correct 17 ms 2320 KB Output is correct
17 Correct 18 ms 2424 KB Output is correct
18 Correct 10 ms 2532 KB Output is correct
19 Correct 20 ms 2644 KB Output is correct
20 Correct 23 ms 2736 KB Output is correct
21 Execution timed out 5014 ms 4212 KB Time limit exceeded
22 Halted 0 ms 0 KB -