Submission #626983

# Submission time Handle Problem Language Result Execution time Memory
626983 2022-08-12T04:05:53 Z socpite Strange Device (APIO19_strange_device) C++14
70 / 100
5000 ms 289988 KB
#include<bits/stdc++.h>
using namespace std;

#define f first
#define s second

typedef long long ll;

const int maxn = 2e6+5;

int n, sz;
ll a, b;

pair<ll, ll> A[maxn];
vector<pair<int, int>> qq[maxn];
map<ll, int> mp;
vector<pair<ll, ll>> rng, vec;
vector<ll> pos;

int main(){
    cin >> n >> a >> b;
    ll cyc = a/__gcd(a, b+1);
    for(int i = 0; i < n; i++){
        cin >> A[i].f >> A[i].s;
        ll lb = A[i].f/b+1, rb = A[i].s/b-1;
        if(rb >= lb){
            if(rb - lb+1 >= cyc)rng.push_back({0, cyc-1});
            else{
                ll lm = lb%cyc, rm = rb%cyc;
                if(lm <= rm)vec.push_back({lm, rm});
                else{
                    vec.push_back({lm, cyc-1});
                    vec.push_back({0, rm});
                }
            }
        }
        pos.push_back(A[i].f%b);
        pos.push_back(A[i].s%b + 1);
    }
    pos.push_back(-1);
    pos.push_back(0);
    pos.push_back(b);
    sort(pos.begin(), pos.end());
    pos.erase(unique(pos.begin(), pos.end()), pos.end());
    sort(vec.begin(), vec.end());
    for(auto v: vec){
        if(rng.empty() || rng.back().s < v.f-1)rng.push_back(v);
        else rng.back().s = max(rng.back().s, v.s);
    }
    sz = pos.size()-1;
    for(int i = 0; i < n; i++){
        ll lb = A[i].f/b, rb = A[i].s/b;
        if(lb == rb){
            int pp = lower_bound(rng.begin(), rng.end(), make_pair(lb%cyc, cyc+1))-rng.begin()-1;
            if(pp < 0 || rng[pp].s < lb%cyc){
                int ql = lower_bound(pos.begin(), pos.end(), A[i].f%b)-pos.begin(), qr = upper_bound(pos.begin(), pos.end(), A[i].s%b) - pos.begin();
                qq[ql].push_back({lb%cyc, 0});
                qq[qr].push_back({lb%cyc, 1});
            }
        }
        else{
            int pp = lower_bound(rng.begin(), rng.end(), make_pair(lb%cyc, cyc+1))-rng.begin()-1;
            if(pp < 0 || rng[pp].s < lb%cyc){
                int ql = lower_bound(pos.begin(), pos.end(), A[i].f%b)-pos.begin();
                qq[ql].push_back({lb%cyc, 0});
            }
            pp = lower_bound(rng.begin(), rng.end(), make_pair(rb%cyc, cyc+1))-rng.begin()-1;
            if(pp < 0 || rng[pp].s < rb%cyc){
                int qr = upper_bound(pos.begin(), pos.end(), A[i].s%b) - pos.begin();
                qq[1].push_back({rb%cyc, 0});
                qq[qr].push_back({rb%cyc, 1});
            }
        }
    }
    int crr = 0;
    ll ans = 0;
    for(int i = 1; i < sz; i++){
        for(auto v: qq[i]){
            if(v.s){
                mp[v.f]--;
                if(!mp[v.f])crr--;
            }
            else{
                if(!mp[v.f])crr++;
                mp[v.f]++;
            }
        }
        ans += (pos[i+1]-pos[i])*crr;
    }
    for(auto v: rng){
        ans+=b*(v.s-v.f+1);
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 26 ms 47188 KB Output is correct
2 Correct 50 ms 48200 KB Output is correct
3 Correct 41 ms 48180 KB Output is correct
4 Correct 24 ms 47160 KB Output is correct
5 Correct 25 ms 47280 KB Output is correct
6 Correct 24 ms 47188 KB Output is correct
7 Correct 25 ms 47204 KB Output is correct
8 Correct 26 ms 47188 KB Output is correct
9 Correct 25 ms 47248 KB Output is correct
10 Correct 26 ms 47276 KB Output is correct
11 Correct 25 ms 47240 KB Output is correct
12 Correct 30 ms 47188 KB Output is correct
13 Correct 26 ms 47384 KB Output is correct
14 Correct 24 ms 47224 KB Output is correct
15 Correct 23 ms 47224 KB Output is correct
16 Correct 45 ms 48164 KB Output is correct
17 Correct 174 ms 56356 KB Output is correct
18 Correct 24 ms 47188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 47208 KB Output is correct
2 Correct 27 ms 47316 KB Output is correct
3 Correct 26 ms 47316 KB Output is correct
4 Correct 24 ms 47188 KB Output is correct
5 Correct 24 ms 47192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 47188 KB Output is correct
2 Correct 24 ms 47424 KB Output is correct
3 Correct 30 ms 47312 KB Output is correct
4 Correct 29 ms 47376 KB Output is correct
5 Correct 1113 ms 151536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 47220 KB Output is correct
2 Correct 1668 ms 194428 KB Output is correct
3 Correct 2066 ms 289764 KB Output is correct
4 Correct 2586 ms 289988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 47220 KB Output is correct
2 Correct 1668 ms 194428 KB Output is correct
3 Correct 2066 ms 289764 KB Output is correct
4 Correct 2586 ms 289988 KB Output is correct
5 Correct 30 ms 47188 KB Output is correct
6 Correct 1996 ms 226896 KB Output is correct
7 Correct 2094 ms 149156 KB Output is correct
8 Correct 2017 ms 226892 KB Output is correct
9 Correct 2488 ms 226928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 47220 KB Output is correct
2 Correct 1668 ms 194428 KB Output is correct
3 Correct 2066 ms 289764 KB Output is correct
4 Correct 2586 ms 289988 KB Output is correct
5 Correct 30 ms 47288 KB Output is correct
6 Correct 217 ms 62720 KB Output is correct
7 Correct 244 ms 66288 KB Output is correct
8 Correct 237 ms 66856 KB Output is correct
9 Correct 272 ms 66820 KB Output is correct
10 Correct 216 ms 61848 KB Output is correct
11 Correct 249 ms 66608 KB Output is correct
12 Correct 277 ms 66488 KB Output is correct
13 Correct 242 ms 66240 KB Output is correct
14 Correct 179 ms 57272 KB Output is correct
15 Correct 324 ms 63804 KB Output is correct
16 Correct 225 ms 57364 KB Output is correct
17 Correct 369 ms 67548 KB Output is correct
18 Correct 3419 ms 235704 KB Output is correct
19 Correct 3694 ms 230372 KB Output is correct
20 Correct 3381 ms 230292 KB Output is correct
21 Correct 441 ms 66104 KB Output is correct
22 Correct 298 ms 66236 KB Output is correct
23 Correct 568 ms 89320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 47188 KB Output is correct
2 Correct 203 ms 57272 KB Output is correct
3 Correct 243 ms 57388 KB Output is correct
4 Correct 3818 ms 169396 KB Output is correct
5 Correct 261 ms 57836 KB Output is correct
6 Correct 274 ms 57800 KB Output is correct
7 Correct 256 ms 57828 KB Output is correct
8 Correct 306 ms 58836 KB Output is correct
9 Correct 337 ms 58752 KB Output is correct
10 Correct 229 ms 57276 KB Output is correct
11 Correct 199 ms 57272 KB Output is correct
12 Correct 203 ms 57204 KB Output is correct
13 Correct 263 ms 57864 KB Output is correct
14 Correct 2105 ms 133060 KB Output is correct
15 Correct 220 ms 56708 KB Output is correct
16 Correct 2102 ms 140704 KB Output is correct
17 Correct 2636 ms 154732 KB Output is correct
18 Correct 23 ms 47180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 47188 KB Output is correct
2 Correct 50 ms 48200 KB Output is correct
3 Correct 41 ms 48180 KB Output is correct
4 Correct 24 ms 47160 KB Output is correct
5 Correct 25 ms 47280 KB Output is correct
6 Correct 24 ms 47188 KB Output is correct
7 Correct 25 ms 47204 KB Output is correct
8 Correct 26 ms 47188 KB Output is correct
9 Correct 25 ms 47248 KB Output is correct
10 Correct 26 ms 47276 KB Output is correct
11 Correct 25 ms 47240 KB Output is correct
12 Correct 30 ms 47188 KB Output is correct
13 Correct 26 ms 47384 KB Output is correct
14 Correct 24 ms 47224 KB Output is correct
15 Correct 23 ms 47224 KB Output is correct
16 Correct 45 ms 48164 KB Output is correct
17 Correct 174 ms 56356 KB Output is correct
18 Correct 24 ms 47188 KB Output is correct
19 Correct 26 ms 47208 KB Output is correct
20 Correct 27 ms 47316 KB Output is correct
21 Correct 26 ms 47316 KB Output is correct
22 Correct 24 ms 47188 KB Output is correct
23 Correct 24 ms 47192 KB Output is correct
24 Correct 24 ms 47188 KB Output is correct
25 Correct 24 ms 47424 KB Output is correct
26 Correct 30 ms 47312 KB Output is correct
27 Correct 29 ms 47376 KB Output is correct
28 Correct 1113 ms 151536 KB Output is correct
29 Correct 30 ms 47220 KB Output is correct
30 Correct 1668 ms 194428 KB Output is correct
31 Correct 2066 ms 289764 KB Output is correct
32 Correct 2586 ms 289988 KB Output is correct
33 Correct 30 ms 47188 KB Output is correct
34 Correct 1996 ms 226896 KB Output is correct
35 Correct 2094 ms 149156 KB Output is correct
36 Correct 2017 ms 226892 KB Output is correct
37 Correct 2488 ms 226928 KB Output is correct
38 Correct 30 ms 47288 KB Output is correct
39 Correct 217 ms 62720 KB Output is correct
40 Correct 244 ms 66288 KB Output is correct
41 Correct 237 ms 66856 KB Output is correct
42 Correct 272 ms 66820 KB Output is correct
43 Correct 216 ms 61848 KB Output is correct
44 Correct 249 ms 66608 KB Output is correct
45 Correct 277 ms 66488 KB Output is correct
46 Correct 242 ms 66240 KB Output is correct
47 Correct 179 ms 57272 KB Output is correct
48 Correct 324 ms 63804 KB Output is correct
49 Correct 225 ms 57364 KB Output is correct
50 Correct 369 ms 67548 KB Output is correct
51 Correct 3419 ms 235704 KB Output is correct
52 Correct 3694 ms 230372 KB Output is correct
53 Correct 3381 ms 230292 KB Output is correct
54 Correct 441 ms 66104 KB Output is correct
55 Correct 298 ms 66236 KB Output is correct
56 Correct 568 ms 89320 KB Output is correct
57 Correct 24 ms 47188 KB Output is correct
58 Correct 203 ms 57272 KB Output is correct
59 Correct 243 ms 57388 KB Output is correct
60 Correct 3818 ms 169396 KB Output is correct
61 Correct 261 ms 57836 KB Output is correct
62 Correct 274 ms 57800 KB Output is correct
63 Correct 256 ms 57828 KB Output is correct
64 Correct 306 ms 58836 KB Output is correct
65 Correct 337 ms 58752 KB Output is correct
66 Correct 229 ms 57276 KB Output is correct
67 Correct 199 ms 57272 KB Output is correct
68 Correct 203 ms 57204 KB Output is correct
69 Correct 263 ms 57864 KB Output is correct
70 Correct 2105 ms 133060 KB Output is correct
71 Correct 220 ms 56708 KB Output is correct
72 Correct 2102 ms 140704 KB Output is correct
73 Correct 2636 ms 154732 KB Output is correct
74 Correct 23 ms 47180 KB Output is correct
75 Correct 29 ms 47256 KB Output is correct
76 Correct 29 ms 47264 KB Output is correct
77 Correct 31 ms 47276 KB Output is correct
78 Correct 29 ms 47200 KB Output is correct
79 Correct 44 ms 48584 KB Output is correct
80 Correct 2246 ms 137836 KB Output is correct
81 Correct 3897 ms 175496 KB Output is correct
82 Correct 4205 ms 239300 KB Output is correct
83 Execution timed out 5024 ms 248808 KB Time limit exceeded
84 Halted 0 ms 0 KB -