Submission #124427

# Submission time Handle Problem Language Result Execution time Memory
124427 2019-07-03T10:27:22 Z amiratou Strange Device (APIO19_strange_device) C++14
5 / 100
661 ms 56332 KB
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define debugii(x) cerr << " - " << #x << ": " << x.fi<<","<<x.se << endl;
#define sep() cerr << "--------------------" << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define ii pair<ll,ll>
#define v vector<int>
#define vii vector<ii>
#define vv vector<vector<int> >
#define mp make_pair
#define INF 1000000000
#define pb push_back
#define EPS 1e-9
const int MOD = 1000000007; // 998244353
ll l[1000005],r[1000005];
vii vec;
int main(){
    boost;
    ll n,A,B;
    cin>>n>>A>>B;
    for (int i = 0; i < n; ++i){
        cin>>l[i]>>r[i];
        //if(!(A&1))l[i]*=2LL,r[i]*=2LL;
    }

    if(A<2){
        cout<<1;return 0;
    }
    if(!(A&1))A/=2;
    for (int i = 0; i < n; ++i)
        {
            if((r[i]-l[i]+1)>=A){vec.pb(ii(0,A-1));break;}
            if((r[i]%A)<(l[i]%A)){
                ll lefty=l[i]%A,righty=A-1;
                vec.pb(ii(lefty,righty));
                lefty=0,righty=r[i]%A;
                vec.pb(ii(lefty,righty));
                continue;
            }
            vec.pb(ii(l[i]%A,r[i]%A));
        }
    sort(all(vec));
    vii final;
    ll lefty=vec[0].fi,righty=vec[0].se;
        for (int i = 1; i < sz(vec); ++i)
        {
            if(vec[i].fi<=righty){
                righty=max(righty,vec[i].se);
            }
            else{
                final.pb(ii(lefty,righty));
                lefty=vec[i].fi,righty=vec[i].se;
            }
        }
    final.pb(ii(lefty,righty));
    ll ans=0;
    for(auto it:final)
        ans+=(it.se-it.fi+1);
    cout<<ans;
    return 0;
}
//long long
//array bounds
//special cases
//binary search
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 8 ms 1016 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 296 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 3 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 661 ms 56296 KB Output is correct
3 Correct 649 ms 56288 KB Output is correct
4 Correct 650 ms 56332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 661 ms 56296 KB Output is correct
3 Correct 649 ms 56288 KB Output is correct
4 Correct 650 ms 56332 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Incorrect 631 ms 39396 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 661 ms 56296 KB Output is correct
3 Correct 649 ms 56288 KB Output is correct
4 Correct 650 ms 56332 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Incorrect 62 ms 4164 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 51 ms 1912 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 8 ms 1016 KB Output isn't correct
3 Halted 0 ms 0 KB -