Submission #468449

#TimeUsernameProblemLanguageResultExecution timeMemory
468449Killer2501Strange Device (APIO19_strange_device)C++14
100 / 100
618 ms92432 KiB
#include <bits/stdc++.h> #define ll long long #define pb push_back #define task "tests" #define pll pair<ll, ll> #define pi pair<ll, pll> #define fi first #define se second using namespace std; const ll mod = 1e18+7; const ll N = 1e6+5; const int base = 313; ll n, m, t, k, T, ans, tong, c[N], a[N], b[N], h[N]; vector<pll> adj[N], kq; ll pw(ll k, ll n) { ll total = 1; for(; n; n >>= 1) { if(n & 1)total = total * k % mod; k = k * k % mod; } return total; } void sol() { ll A, B; cin >> n >> A >> B; A /= __gcd(A, B+1); if(A > mod / B)tong = mod; else tong = A * B; for(int i = 0; i < n; i ++) { cin >> a[i] >> b[i]; if(b[i]-a[i]+1 >= tong) { cout << tong; return; } a[i] %= tong; b[i] %= tong; if(a[i] <= b[i])kq.pb({a[i], b[i]}); else { kq.pb({0, b[i]}); kq.pb({a[i], tong-1}); } } sort(kq.begin(), kq.end()); ll l = kq[0].fi, r = kq[0].se; ans = r-l+1; for(int i = 1; i < kq.size(); i ++) { if(kq[i].fi > r) { ans += kq[i].se - kq[i].fi + 1; l = kq[i].fi; r = kq[i].se; } else { ans += max(0ll, kq[i].se-r); r = max(kq[i].se, r); } } cout << ans; } int main() { if(fopen(task".in", "r")) { freopen(task".in", "r", stdin); freopen(task".out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int ntest = 1; //cin >> ntest; while(ntest -- > 0) sol(); } /* 5 1 0 1 2 0 2 3 1 3 5 2 4 6 1 1 4 3 */

Compilation message (stderr)

strange_device.cpp: In function 'void sol()':
strange_device.cpp:54:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |     for(int i = 1; i < kq.size(); i ++)
      |                    ~~^~~~~~~~~~~
strange_device.cpp: In function 'int main()':
strange_device.cpp:74:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |        freopen(task".in", "r", stdin);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:75:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |        freopen(task".out", "w", stdout);
      |        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...