| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1339625 | danglayloi1 | Strange Device (APIO19_strange_device) | C++20 | 339 ms | 16976 KiB |
#include <bits/stdc++.h>
#define ii pair<int, int>
#define fi first
#define se second
#define inf 0x3f3f3f3f3f3f3f3f
using namespace std;
using ll = long long;
const ll mod=1e9+7;
const ll lim=1e18;
int n;
ll A, B, res=0;
vector<pair<ll, ll>> ve;
pair<ll, ll> cur={-1, -2};
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin>>n>>A>>B;
A/=__gcd(A, B+1);
if(A>lim/B-1)
{
while(n--)
{
ll l, r;
cin>>l>>r;
res+=r-l+1;
}
return cout<<res, 0;
}
A*=B;
while(n--)
{
ll l, r;
cin>>l>>r;
if(r/A-l/A<=1)
{
l%=A;
r%=A;
if(l<=r) ve.emplace_back(l, r);
else
{
ve.emplace_back(0, r);
ve.emplace_back(l, A-1);
}
}
else ve.emplace_back(0, A-1);
}
sort(ve.begin(), ve.end());
for(auto it:ve)
{
if(it.fi>cur.se+1)
{
res+=cur.se-cur.fi+1;
cur=it;
}
else cur.se=max(cur.se, it.se);
}
res+=cur.se-cur.fi+1;
cout<<res;
}
| # | 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... | ||||
