제출 #264776

#제출 시각아이디문제언어결과실행 시간메모리
264776dimash241이상한 기계 (APIO19_strange_device)C++17
100 / 100
580 ms53476 KiB
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops") //#pragma GCC target("avx,avx2") //#pragma GCC target("avx2") //#pragma GCC optimize("O3") //# include <x86intrin.h> # include <bits/stdc++.h> # include <ext/pb_ds/assoc_container.hpp> # include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define _USE_MATH_DEFINES_ #define ll long long #define ld long double #define Accepted 0 #define pb push_back #define mp make_pair #define sz(x) (int)(x.size()) #define every(x) x.begin(),x.end() #define F first #define S second #define lb lower_bound #define ub upper_bound #define For(i,x,y) for (ll i = x; i <= y; i ++) #define FOr(i,x,y) for (ll i = x; i >= y; i --) #define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0) // ROAD to... Red void setIn(string s) { freopen(s.c_str(),"r",stdin); } void setOut(string s) { freopen(s.c_str(),"w",stdout); } void setIO(string s = "") { // cin.exceptions(cin.failbit); // throws exception when do smth illegal // ex. try to read letter into int if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO } const double eps = 0.000001; const ld pi = acos(-1); const int maxn = 1e7 + 9; const int mod = 1e9 + 7; const ll MOD = 1e18 + 9; const ll INF = 1e18 + 123; const int inf = 2e9 + 11; const int mxn = 1e6 + 9; const int N = 6e5 + 123; const int M = 22; const int pri = 997; const int Magic = 2101; const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, -1, 0, 1}; mt19937 gen(chrono::steady_clock::now().time_since_epoch().count()); int rnd (int l, int r) { return uniform_int_distribution<int> (l, r)(gen); } int n; ll a, b; vector < pair <ll, ll > > p; int main () { SpeedForce; cin >> n >> a >> b; p.resize(n); for (auto &e : p) cin >> e.first >> e.second; a = a / __gcd(a,b+1); if (INF / a < b) { ll ans = 0; for (auto e : p) ans += e.second - e.first + 1; cout << ans << '\n'; exit(0); } a *= b; vector < pair<ll, ll> > e; for (auto it : p) { if((ll)(it.first / a) + 1 < (ll)it.second / a) { cout << a << '\n'; exit(0); } if (it.second/a == it.first/a) e.pb({it.first%a, it.second%a}); else { e.pb({it.first % a, a-1}); e.pb({0, it.second % a}); } } sort(every(e)); ll ans = 0; for (int i = 0; i < sz(e); ++i) { ll l, r; tie(l,r) = e[i]; int j = i; while(j + 1 < sz(e) && e[j+1].first <= r) { ++j; r = max(r, e[j].second); } ans += r - l + 1; i = j; } cout << ans << '\n'; return Accepted; } // B...a

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

strange_device.cpp: In function 'void setIn(std::string)':
strange_device.cpp:34:31: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   34 | void setIn(string s) { freopen(s.c_str(),"r",stdin); }
      |                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
strange_device.cpp: In function 'void setOut(std::string)':
strange_device.cpp:35:32: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   35 | void setOut(string s) { freopen(s.c_str(),"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...