Submission #974743

# Submission time Handle Problem Language Result Execution time Memory
974743 2024-05-03T17:53:36 Z Abito Strange Device (APIO19_strange_device) C++17
0 / 100
688 ms 102056 KB
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define ep insert
#define endl '\n'
#define elif else if
#define pow pwr
#define sqrt sqrtt
#define int long long
typedef unsigned long long ull;
using namespace std;
const int N=1e6+5;
int l[3][N],r[3][N],n,a,b;
int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    cin>>n>>a>>b;
    a/=__gcd(a,b+1);
    for (int i=1;i<=n;i++){
        int L,R;cin>>L>>R;
        for (int m=0;m<b;m++){
            int ll=0,rr=1e18/b,mid,lx=-1,rx=-1;
            while (ll<=rr){
                mid=ll+(rr-ll)/2;
                if (mid*b+m>=L){
                    lx=mid;
                    rr=mid-1;
                }else ll=mid+1;
            }
            ll=0,rr=1e18/b;
            while (ll<=rr){
                mid=ll+(rr-ll)/2;
                if (mid*b+m<=R){
                    rx=mid;
                    ll=mid+1;
                }else rr=mid-1;
            }
            if (lx>rx) l[m][i]=r[m][i]=-1;
            else{
            l[m][i]=lx;
            r[m][i]=rx;}
        }
    }
    int ans=0;
    for (int m=0;m<b;m++){
        vector<pair<int,int>> v;
        for (int i=1;i<=n;i++){
            if (l[m][i]==-1) continue;
            if (r[i]-l[i]+1>=a) v.pb({0,a-1});
            else{
                int L=((l[m][i]-m)/(b+1))%a;
                int R=((r[m][i]-m)/(b+1))%a;
                if (R>=L) v.pb({L,R});
                else{
                    v.pb({L,a-1});
                    v.pb({0,R});
                }
            }
        }
        if (v.empty()) continue;
        sort(v.begin(),v.end());
        //for (auto u:v) cout<<u.F<<' '<<u.S<<endl;
        set<pair<int,int>> s;
        pair<int,int> cur=v[0];
        for (int i=0;i<v.size();i++){
            int l=max(cur.F,v[i].F),r=min(cur.S,v[i].S);
            if (l>r){
                s.ep(cur);
                cur=v[i];
            }
            else{
                cur.F=min(cur.F,v[i].F);
                cur.S=max(cur.S,v[i].S);
            }
        }
        s.ep(cur);
        for (auto u:s) ans+=u.S-u.F+1;
    }cout<<ans<<endl;
    return 0;
}

Compilation message

strange_device.cpp: In function 'int32_t main()':
strange_device.cpp:66:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |         for (int i=0;i<v.size();i++){
      |                      ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Runtime error 12 ms 21340 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Runtime error 11 ms 21340 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Runtime error 13 ms 21340 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2508 KB Output is correct
2 Incorrect 688 ms 102056 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2508 KB Output is correct
2 Incorrect 688 ms 102056 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2508 KB Output is correct
2 Incorrect 688 ms 102056 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Runtime error 10 ms 21224 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Runtime error 12 ms 21340 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -