제출 #729715

#제출 시각아이디문제언어결과실행 시간메모리
729715danikoynov이상한 기계 (APIO19_strange_device)C++14
5 / 100
1616 ms49784 KiB
#include<bits/stdc++.h> #define endl '\n' using namespace std; typedef long long ll; void speed() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } const int maxn = 1e6 + 10; int n; ll l[maxn], r[maxn]; ll A, B; struct point { ll x, t; point(ll _x = 0, ll _t = 0) { x = _x; t = _t; } bool operator < (const point &p) const { if (x == p.x) return t > p.t; return x < p.x; } }; vector < point > vec; void add_segment(ll l, ll r) { vec.push_back(point(l, 1)); vec.push_back(point(r, -1)); } void solve() { cin >> n >> A >> B; for (int i = 1; i <= n; i ++) { cin >> l[i] >> r[i]; } ll period = 1e18 + 10; ll g = __gcd(A, B + 1); if ((double)(A) * (double)(B) / (double)(g) < (double)period) period = A * B / g; for (int i = 1; i <= n; i ++) { if (r[i] - l[i] + 1 >= period) { cout << period << endl; return; } ll x = l[i] % period, y = r[i] % period; if (x <= y) { add_segment(x, y); } else { add_segment(0, y); add_segment(x, period); } } sort(vec.begin(), vec.end()); ll ans = 0, cnt = 0; ll st = -1; for (int i = 0; i < vec.size(); i ++) { ///cout << vec[i].x << " " << vec[i].t << endl; if (vec[i].t == 1) { if (cnt) cnt ++; else { st = vec[i].x; cnt = 1; } } else { if (cnt > 1) cnt --; else { ans = ans + vec[i].x - st + 1; cnt = 0; } } } cout << ans << endl; } int main() { solve(); return 0; } /** 1 10000 3312452154131231 1 1 */

컴파일 시 표준 에러 (stderr) 메시지

strange_device.cpp: In function 'void solve()':
strange_device.cpp:84:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |     for (int i = 0; i < vec.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...