Submission #781656

# Submission time Handle Problem Language Result Execution time Memory
781656 2023-07-13T09:14:10 Z andecaandeci Strange Device (APIO19_strange_device) C++17
20 / 100
474 ms 40724 KB
#include<bits/stdc++.h>
#define int long long
#define pii pair<int, int>
using namespace std;
const int MAX=1e18;
signed main() {
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  int n, a, b; cin >> n >> a >> b;
  priority_queue<pii, vector<pii>, greater<pii>> pq;
  int S=0;
  bool cut=1;
    while(n--) {
      int l, r; cin >> l >> r;
      pq.push({l, r});
      S+=r-l+1;
      if(S>(int)1e6) cut=0, S=0;
    }
    if(cut) {
      set<pair<int, int>> ans;
      while(!pq.empty()) {
      int i=pq.top().first, j=pq.top().second;
      pq.pop();
        while(i<=j) {
        while(!pq.empty() && pq.top().first==i) j=max(j, pq.top().second);
          ans.insert({(i+i/b)%a, i%b});
            i++;
        }
      }
      cout << ans.size() << '\n';
  } else {
    priority_queue<pii, vector<pii>, greater<pii>> to_ans;
      int Mod;
      if(a>(MAX+b-1)/b) Mod=1e18+1;
      else Mod=a*b;
      while(!pq.empty()) {
        int l=pq.top().first, r=pq.top().second;
        pq.pop();
        while(!pq.empty() && pq.top().first<=r) r=max(r, pq.top().second), pq.pop();
      if((l+Mod-1)/Mod*Mod+Mod-1<=r) {cout << Mod << '\n'; return 0;}
        if((l+Mod-1)/Mod*Mod<=r && l%Mod) to_ans.push({l%Mod, Mod-1}), to_ans.push({0, r%Mod});
        else to_ans.push({l%Mod, r%Mod});
      }
      int ans=0;
      while(!to_ans.empty()) {
        int l=to_ans.top().first, r=to_ans.top().second;
        to_ans.pop();
        while(!to_ans.empty() && to_ans.top().first<=r) r=max(r, to_ans.top().second), to_ans.pop(); 
      ans+=r-l+1;
    }
    cout << ans << '\n';
  }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 37 ms 12484 KB Output is correct
3 Correct 60 ms 18056 KB Output is correct
4 Correct 2 ms 852 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 7 ms 1108 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 33 ms 6916 KB Output is correct
16 Correct 22 ms 6848 KB Output is correct
17 Correct 52 ms 8164 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 102 ms 32168 KB Output is correct
3 Correct 131 ms 31948 KB Output is correct
4 Correct 107 ms 30580 KB Output is correct
5 Correct 451 ms 40564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 474 ms 40512 KB Output is correct
3 Incorrect 453 ms 40724 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 474 ms 40512 KB Output is correct
3 Incorrect 453 ms 40724 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 474 ms 40512 KB Output is correct
3 Incorrect 453 ms 40724 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 43 ms 4904 KB Output is correct
3 Correct 42 ms 4956 KB Output is correct
4 Correct 446 ms 40584 KB Output is correct
5 Correct 40 ms 4984 KB Output is correct
6 Correct 40 ms 4948 KB Output is correct
7 Correct 40 ms 4968 KB Output is correct
8 Correct 42 ms 4964 KB Output is correct
9 Correct 50 ms 4868 KB Output is correct
10 Correct 42 ms 4940 KB Output is correct
11 Correct 43 ms 4940 KB Output is correct
12 Correct 42 ms 4940 KB Output is correct
13 Correct 45 ms 4952 KB Output is correct
14 Correct 462 ms 40544 KB Output is correct
15 Incorrect 42 ms 4924 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 37 ms 12484 KB Output is correct
3 Correct 60 ms 18056 KB Output is correct
4 Correct 2 ms 852 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 7 ms 1108 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 33 ms 6916 KB Output is correct
16 Correct 22 ms 6848 KB Output is correct
17 Correct 52 ms 8164 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 102 ms 32168 KB Output is correct
26 Correct 131 ms 31948 KB Output is correct
27 Correct 107 ms 30580 KB Output is correct
28 Correct 451 ms 40564 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 474 ms 40512 KB Output is correct
31 Incorrect 453 ms 40724 KB Output isn't correct
32 Halted 0 ms 0 KB -