Submission #363983

#TimeUsernameProblemLanguageResultExecution timeMemory
363983MahdiBahramianStrange Device (APIO19_strange_device)C++11
100 / 100
2016 ms106888 KiB
#include<bits/stdc++.h> #define F first #define S second #define mp make_pair #define pb push_back #define int ll using namespace std; typedef long long ll; const ll INF = 2e18 + 1000; const int Max = 4e6 + 10; ll L[Max] , R[Max]; vector<ll> compress; unordered_map<ll , int> cnv; int ps[Max]; int val[Max]; int32_t main() { ll n , A , B; cin >> n >> A >> B; ll SUM = 0; for(int i = 1 ; i <= n ; i++) { cin >> L[i] >> R[i]; SUM += R[i] - L[i] + 1; } if(A / __gcd(A , B + 1) > INF / B) { cout << SUM << '\n'; return 0; } ll md = A * B / __gcd(A , B + 1); vector<pair<int , int>> vec; for(int i = 1 ; i <= n ; i++) { if(R[i] - L[i] + 1 >= md) { cout << md << '\n'; return 0; } R[i] %= md; L[i] %= md; compress.pb(L[i]); compress.pb(R[i] + 1); if(R[i] < L[i]) { vec.pb(mp(0 , R[i])); vec.pb(mp(L[i] , md - 1)); } else vec.pb(mp(L[i] , R[i])); } compress.pb(0); compress.pb(md); sort(compress.begin() , compress.end()); compress.resize(unique(compress.begin() , compress.end()) - compress.begin()); for(int i = 0 ; i < compress.size() ; i++) cnv[compress[i]] = i; for(int i = 0 ; i < vec.size() ; i++) { //cout << vec[i].F << ',' << vec[i].S << '\n'; val[cnv[vec[i].F]]++; val[cnv[vec[i].S + 1]]--; } for(int i = 1 ; i < compress.size() ; i++) val[i] += val[i - 1]; ll res = 0; for(int i = 0 ; i < compress.size() - 1 ; i++) { if(val[i] >= 1) { res += compress[i + 1] - compress[i]; } } cout << '\n'; cout << res << '\n'; }

Compilation message (stderr)

strange_device.cpp: In function 'int32_t main()':
strange_device.cpp:57:20: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |  for(int i = 0 ; i < compress.size() ; i++) cnv[compress[i]] = i;
      |                  ~~^~~~~~~~~~~~~~~~~
strange_device.cpp:59:20: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |  for(int i = 0 ; i < vec.size() ; i++)
      |                  ~~^~~~~~~~~~~~
strange_device.cpp:65:20: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |  for(int i = 1 ; i < compress.size() ; i++) val[i] += val[i - 1];
      |                  ~~^~~~~~~~~~~~~~~~~
strange_device.cpp:67:20: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |  for(int i = 0 ; i < compress.size() - 1 ; 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...