Submission #781642

# Submission time Handle Problem Language Result Execution time Memory
781642 2023-07-13T09:06:45 Z christinelynn Strange Device (APIO19_strange_device) C++17
20 / 100
487 ms 42716 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 0 ms 212 KB Output is correct
2 Correct 36 ms 12500 KB Output is correct
3 Correct 59 ms 18012 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 6 ms 1204 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 34 ms 7032 KB Output is correct
16 Correct 24 ms 6872 KB Output is correct
17 Correct 59 ms 8100 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 1 ms 316 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 1 ms 212 KB Output is correct
2 Correct 114 ms 32292 KB Output is correct
3 Correct 135 ms 31960 KB Output is correct
4 Correct 127 ms 30616 KB Output is correct
5 Correct 424 ms 42716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 487 ms 40600 KB Output is correct
3 Incorrect 452 ms 40888 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 487 ms 40600 KB Output is correct
3 Incorrect 452 ms 40888 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 487 ms 40600 KB Output is correct
3 Incorrect 452 ms 40888 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 4940 KB Output is correct
3 Correct 48 ms 7864 KB Output is correct
4 Correct 459 ms 40900 KB Output is correct
5 Correct 44 ms 7824 KB Output is correct
6 Correct 49 ms 7892 KB Output is correct
7 Correct 46 ms 7880 KB Output is correct
8 Correct 44 ms 7928 KB Output is correct
9 Correct 45 ms 8028 KB Output is correct
10 Correct 47 ms 7844 KB Output is correct
11 Correct 43 ms 7860 KB Output is correct
12 Correct 43 ms 7904 KB Output is correct
13 Correct 47 ms 7872 KB Output is correct
14 Correct 433 ms 40916 KB Output is correct
15 Incorrect 43 ms 8572 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 36 ms 12500 KB Output is correct
3 Correct 59 ms 18012 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 6 ms 1204 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 34 ms 7032 KB Output is correct
16 Correct 24 ms 6872 KB Output is correct
17 Correct 59 ms 8100 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 1 ms 316 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 114 ms 32292 KB Output is correct
26 Correct 135 ms 31960 KB Output is correct
27 Correct 127 ms 30616 KB Output is correct
28 Correct 424 ms 42716 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 487 ms 40600 KB Output is correct
31 Incorrect 452 ms 40888 KB Output isn't correct
32 Halted 0 ms 0 KB -