Submission #404762

#TimeUsernameProblemLanguageResultExecution timeMemory
404762gevacrtStrange Device (APIO19_strange_device)C++17
20 / 100
1624 ms524292 KiB
#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(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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...