Submission #404763

# Submission time Handle Problem Language Result Execution time Memory
404763 2021-05-15T00:08:00 Z gevacrt Strange Device (APIO19_strange_device) C++17
20 / 100
1509 ms 524292 KB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define int ll

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

#define INF INT_MAX
#define MOD 1000000007
#define all(x) x.begin(), x.end()

namespace DST {
    struct node {
        int sum{}, lazy{}, tot{};
        node *l = NULL, *r = NULL;
    };
    auto root = new node;

    void upd(node *n, int l, int r){
        if(!n) return;
        if(n->sum) n->tot = r-l+1;
        else{
            n->tot = 0;
            if(n->l) n->tot += n->l->tot;
            if(n->r) n->tot += n->r->tot;
        }
        return;
    }

    void update(node *n, int l, int r, int L, int R, int val){
        if(r < L or R < l) return;
        if(n->sum) return;

        if(L <= l and r <= R){
            n->sum += val;
            upd(n, l, r);
            return;
        }

        if(!n->l) n->l = new node;
        if(!n->r) n->r = new node;

        int m = (l+r)/2;
        update(n->l, l, m, L, R, val);
        update(n->r, m+1, r, L, R, val);
        upd(n, l, r);
    }

    void update(int L, int R, int val){
        update(root, 0, 1e18+10, L, R, val);
    }

    int query(){
        return root->tot;
    }
};


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int Q, A, B; cin >> Q >> A >> B;
    int A1 = A/__gcd(A, B+1);

    if(A1 <= int(1e18)/B) A1 *= B;
    else A1 = 1e18+10;

    while(Q--){
        int l, r; cin >> l >> r;
        if(r-l+1 >= A1) DST::update(0, A1-1, 1);
        else{
            int lm = l%A1, rm = r%A1;
            if(lm <= rm) DST::update(lm, rm, 1);
            else DST::update(lm, A1-1, 1), DST::update(0, rm, 1);
        }
    }

    cout << DST::query() << endl;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 19 ms 3980 KB Output is correct
3 Correct 20 ms 4892 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 24 ms 3552 KB Output is correct
17 Correct 146 ms 10100 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 252 KB Output is correct
2 Correct 3 ms 1228 KB Output is correct
3 Correct 4 ms 1172 KB Output is correct
4 Correct 3 ms 1148 KB Output is correct
5 Correct 1388 ms 300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1509 ms 94280 KB Output is correct
3 Runtime error 1150 ms 524292 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1509 ms 94280 KB Output is correct
3 Runtime error 1150 ms 524292 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1509 ms 94280 KB Output is correct
3 Runtime error 1150 ms 524292 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 229 ms 62876 KB Output is correct
3 Correct 336 ms 147708 KB Output is correct
4 Runtime error 1041 ms 524292 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 19 ms 3980 KB Output is correct
3 Correct 20 ms 4892 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 24 ms 3552 KB Output is correct
17 Correct 146 ms 10100 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 252 KB Output is correct
25 Correct 3 ms 1228 KB Output is correct
26 Correct 4 ms 1172 KB Output is correct
27 Correct 3 ms 1148 KB Output is correct
28 Correct 1388 ms 300 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1509 ms 94280 KB Output is correct
31 Runtime error 1150 ms 524292 KB Execution killed with signal 9
32 Halted 0 ms 0 KB -