# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
203149 | Mercenary | Strange Device (APIO19_strange_device) | C++14 | 810 ms | 53524 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#define pb push_back
#define mp make_pair
#define taskname "A"
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const int maxn = 2e5 + 5;
const int mod = 1e9 + 7;
int n;
ll A , B;
const ll inf = (ll)1e18 + 3;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
if(fopen(taskname".INP","r")){
freopen(taskname".INP", "r",stdin);
freopen(taskname".OUT", "w",stdout);
}
cin >> n >> A >> B;
ll d = __gcd(A,B+1);A /= d;
if(A > inf / B)A = inf;
else A *= B;
vector<pair<ll,ll>> val;
while(n--){
ll l ,r;cin >> l >> r;
if(r - l + 1 >= A)tie(l,r) = mp(0,A-1);
l %= A;r %= A;
// cout << l << " " << r << endl;
if(l <= r)val.pb(mp(l,r));
else val.pb(mp(0,r)),val.pb(mp(l,A-1));
}
sort(val.begin(),val.end());
ll cur = 0 , res = 0;
for(auto c : val){
if(cur <= c.second){
res += c.second - max(cur,c.first) + 1;
}
// cout << c.first << " " << c.second << " " << cur << " " << res << endl;
cur = max(cur,c.second+1);
}
cout << res;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |