Submission #985098

# Submission time Handle Problem Language Result Execution time Memory
985098 2024-05-17T10:35:36 Z SyedSohaib_123 Strange Device (APIO19_strange_device) C++17
100 / 100
1838 ms 112432 KB
#include<bits/stdc++.h>
 
 
 
using namespace std;
 
 
 
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
 
 
 
#define str string
#define append push_back
#define vector deque
#define vi vector<int>
#define int long long
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define endl '\n'
#define all(ls) ls.begin(),ls.end()
#define sorted(ls) sort(ls.begin(),ls.end());
#define reversed(ls) reverse(ls.begin(),ls.end());
#define print(n) for(auto i:n)cout<<i<<' ';cout<<endl;
#define input(n,ls,m) deque<n>ls(m);for(int i=0;i<m;i++)cin>>ls[i];
#define len(s) s.size()
#define ff first
#define ss second
#define N (int const) 3e5+1
#define pii pair<int,int>
#define SQ(x) ((x)*(x))
#define float double
 
 
int mod=1e9+7;
int mod1=998244353;
 
 
 
int sum_(vector<int>ls){int s=0;for(auto i:ls){s+=i;}return s;}
int min(int a,int b){if (a>b){return b;}return a;}
int max(int a,int b){if (a<b){return b;}return a;}
 
 
 
//......................................tHe ReaL cOdE beGinS HerE....................................../



int solve2(vector<pii> ls,int a,int b){
    map<pair<int,int>,bool>m;
    for(auto i:ls){
        for(int j=i.ff;j<=i.ss;j++){
            m[{(j+j/b)%a,j%b}]=1;
        }
    }
    return len(m);
}


 
void solve(){
    int n,a,b;
    cin>>n>>a>>b;
    vector<pii>ls;
    int cnt=0;
    for(int i=0;i<n;i++){
        int x,y;
        cin>>x>>y;
        cnt+=y-x+1;
        ls.append({x,y});
    }
    if(cnt<=1e6){cout<<solve2(ls,a,b)<<endl;return;}
    a/=gcd(a,b+1);
    a*=b;
    for(auto i:ls){
        if(i.ss-i.ff+1>=a){
            cout<<a<<endl;return;
        }
    }
    vector<pii>q;
    for(auto i:ls){
        int f=i.ff%a,s=i.ss%a;
        if(f<s or i.ff==i.ss) q.append({f,s});
        else{
            q.append({f,a-1});
            q.append({0,s});
        }
    }
    sorted(q);
    map<int,int>hlpr;
    for(auto i:q) hlpr[i.ff]=i.ss;
    vector<pii>q2;
    for(auto i:hlpr) q2.append(i);
    hlpr.clear();
    swap(q2,q);
    for(int i=1;i<q.size();i++){
        if(q[i-1].ss>=q[i].ff){
            q[i].ss=max(q[i].ss,q[i-1].ss);
            q[i].ff=q[i-1].ff;
            hlpr[i-1]=1;
        }
    }
    q2.clear();
    int ans=0;
    for(int i=0;i<q.size();i++){
        if(hlpr[i]){continue;}
        ans+=q[i].ss-q[i].ff+1;
    }
    cout<<ans<<endl;

}
 
 
 
 
 
signed main(){
    int t=1;
    // cin>>t;
    while(t--)
        solve();
}

Compilation message

strange_device.cpp: In function 'void solve()':
strange_device.cpp:99:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::deque<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   99 |     for(int i=1;i<q.size();i++){
      |                 ~^~~~~~~~~
strange_device.cpp:108:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::deque<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  108 |     for(int i=0;i<q.size();i++){
      |                 ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 48 ms 12636 KB Output is correct
3 Correct 73 ms 18256 KB Output is correct
4 Correct 2 ms 860 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 2 ms 856 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 6 ms 1336 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 38 ms 7004 KB Output is correct
16 Correct 34 ms 7224 KB Output is correct
17 Correct 119 ms 9816 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 138 ms 32384 KB Output is correct
3 Correct 191 ms 32200 KB Output is correct
4 Correct 116 ms 30820 KB Output is correct
5 Correct 749 ms 33288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1491 ms 112072 KB Output is correct
3 Correct 1519 ms 112080 KB Output is correct
4 Correct 1441 ms 112036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1491 ms 112072 KB Output is correct
3 Correct 1519 ms 112080 KB Output is correct
4 Correct 1441 ms 112036 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1474 ms 112244 KB Output is correct
7 Correct 1838 ms 112244 KB Output is correct
8 Correct 1469 ms 112240 KB Output is correct
9 Correct 1630 ms 112236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1491 ms 112072 KB Output is correct
3 Correct 1519 ms 112080 KB Output is correct
4 Correct 1441 ms 112036 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 142 ms 11476 KB Output is correct
7 Correct 132 ms 11436 KB Output is correct
8 Correct 152 ms 11480 KB Output is correct
9 Correct 134 ms 11456 KB Output is correct
10 Correct 136 ms 11604 KB Output is correct
11 Correct 139 ms 11416 KB Output is correct
12 Correct 152 ms 11516 KB Output is correct
13 Correct 171 ms 11596 KB Output is correct
14 Correct 132 ms 11600 KB Output is correct
15 Correct 147 ms 11440 KB Output is correct
16 Correct 137 ms 11392 KB Output is correct
17 Correct 138 ms 11464 KB Output is correct
18 Correct 1517 ms 112064 KB Output is correct
19 Correct 1455 ms 112240 KB Output is correct
20 Correct 1558 ms 112240 KB Output is correct
21 Correct 147 ms 11596 KB Output is correct
22 Correct 141 ms 11604 KB Output is correct
23 Correct 361 ms 11468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 153 ms 11380 KB Output is correct
3 Correct 136 ms 11596 KB Output is correct
4 Correct 1557 ms 112288 KB Output is correct
5 Correct 159 ms 11420 KB Output is correct
6 Correct 137 ms 11600 KB Output is correct
7 Correct 150 ms 11360 KB Output is correct
8 Correct 138 ms 11600 KB Output is correct
9 Correct 138 ms 11600 KB Output is correct
10 Correct 165 ms 11768 KB Output is correct
11 Correct 155 ms 11464 KB Output is correct
12 Correct 135 ms 11448 KB Output is correct
13 Correct 138 ms 11528 KB Output is correct
14 Correct 1538 ms 112068 KB Output is correct
15 Correct 141 ms 11464 KB Output is correct
16 Correct 1499 ms 112084 KB Output is correct
17 Correct 1426 ms 112164 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 48 ms 12636 KB Output is correct
3 Correct 73 ms 18256 KB Output is correct
4 Correct 2 ms 860 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 2 ms 856 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 6 ms 1336 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 38 ms 7004 KB Output is correct
16 Correct 34 ms 7224 KB Output is correct
17 Correct 119 ms 9816 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 138 ms 32384 KB Output is correct
26 Correct 191 ms 32200 KB Output is correct
27 Correct 116 ms 30820 KB Output is correct
28 Correct 749 ms 33288 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1491 ms 112072 KB Output is correct
31 Correct 1519 ms 112080 KB Output is correct
32 Correct 1441 ms 112036 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1474 ms 112244 KB Output is correct
35 Correct 1838 ms 112244 KB Output is correct
36 Correct 1469 ms 112240 KB Output is correct
37 Correct 1630 ms 112236 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 142 ms 11476 KB Output is correct
40 Correct 132 ms 11436 KB Output is correct
41 Correct 152 ms 11480 KB Output is correct
42 Correct 134 ms 11456 KB Output is correct
43 Correct 136 ms 11604 KB Output is correct
44 Correct 139 ms 11416 KB Output is correct
45 Correct 152 ms 11516 KB Output is correct
46 Correct 171 ms 11596 KB Output is correct
47 Correct 132 ms 11600 KB Output is correct
48 Correct 147 ms 11440 KB Output is correct
49 Correct 137 ms 11392 KB Output is correct
50 Correct 138 ms 11464 KB Output is correct
51 Correct 1517 ms 112064 KB Output is correct
52 Correct 1455 ms 112240 KB Output is correct
53 Correct 1558 ms 112240 KB Output is correct
54 Correct 147 ms 11596 KB Output is correct
55 Correct 141 ms 11604 KB Output is correct
56 Correct 361 ms 11468 KB Output is correct
57 Correct 1 ms 344 KB Output is correct
58 Correct 153 ms 11380 KB Output is correct
59 Correct 136 ms 11596 KB Output is correct
60 Correct 1557 ms 112288 KB Output is correct
61 Correct 159 ms 11420 KB Output is correct
62 Correct 137 ms 11600 KB Output is correct
63 Correct 150 ms 11360 KB Output is correct
64 Correct 138 ms 11600 KB Output is correct
65 Correct 138 ms 11600 KB Output is correct
66 Correct 165 ms 11768 KB Output is correct
67 Correct 155 ms 11464 KB Output is correct
68 Correct 135 ms 11448 KB Output is correct
69 Correct 138 ms 11528 KB Output is correct
70 Correct 1538 ms 112068 KB Output is correct
71 Correct 141 ms 11464 KB Output is correct
72 Correct 1499 ms 112084 KB Output is correct
73 Correct 1426 ms 112164 KB Output is correct
74 Correct 1 ms 348 KB Output is correct
75 Correct 1 ms 348 KB Output is correct
76 Correct 0 ms 348 KB Output is correct
77 Correct 0 ms 348 KB Output is correct
78 Correct 0 ms 348 KB Output is correct
79 Correct 19 ms 1372 KB Output is correct
80 Correct 1624 ms 112392 KB Output is correct
81 Correct 1522 ms 112228 KB Output is correct
82 Correct 1497 ms 112060 KB Output is correct
83 Correct 1535 ms 112096 KB Output is correct
84 Correct 1502 ms 112432 KB Output is correct
85 Correct 1495 ms 112016 KB Output is correct
86 Correct 330 ms 11404 KB Output is correct
87 Correct 1 ms 348 KB Output is correct