Submission #985082

#TimeUsernameProblemLanguageResultExecution timeMemory
985082SyedSohaib_123Strange Device (APIO19_strange_device)C++17
100 / 100
1731 ms149584 KiB
#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 (stderr)

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 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...