# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
736307 | definitelynotmee | Strange Device (APIO19_strange_device) | C++98 | 482 ms | 32636 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>
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
using namespace std;
template <typename T>
using bstring = basic_string<T>;
template <typename T>
using matrix = vector<vector<T>>;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll INFL = (1LL<<62)-1;
const int INF = (1<<30)-1;
const double EPS = 1e-7;
const int MOD = 998244353;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
const ll MAXN = 1e18+10;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
ll n, a, b;
cin >> n >> a >> b;
if(a%(b+1) == 0)
a/=b+1;
bool beeg = (MAXN+b-1)/b < a;
vector<pll> v(n);
ll resp = 0;
vector<pll> interval;
for(auto& [l, r] : v){
cin >> l >> r;
if(beeg){
resp+=r-l+1;
} else {
if(r-l >= a*b){
cout << a*b << '\n';
return 0;
}
ll tl = l%(a*b), tr = r%(a*b);
if(tl <= tr){
interval.push_back({tl,tr});
} else {
interval.push_back({tl,a*b-1});
interval.push_back({0,tr});
}
}
}
if(beeg){
cout << resp << '\n';
return 0;
}
sort(all(interval));
ll counted = -1;
for(auto [l,r] : interval){
if(counted < l){
resp+=r-l+1;
counted = r;
} else {
resp+=r-counted;
counted = r;
}
}
cout << resp << '\n';
return 0;
}
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... |