Submission #974758

# Submission time Handle Problem Language Result Execution time Memory
974758 2024-05-03T18:39:10 Z Abito Strange Device (APIO19_strange_device) C++17
5 / 100
1621 ms 149572 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;
    int g=__gcd(a,b+1);
    a/=g;
    int step=(b+1)/g;
    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 (l[m][i]-r[m][i]>=(a/__gcd(a,b+1))) {v.pb({0,a-1});continue;}
            int L=(l[m][i])%a;
            int R=(r[m][i])%a;
            if (L<=R){
                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:68: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]
   68 |         for (int i=0;i<v.size();i++){
      |                      ~^~~~~~~~~
strange_device.cpp:21:9: warning: unused variable 'step' [-Wunused-variable]
   21 |     int step=(b+1)/g;
      |         ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Runtime error 11 ms 21364 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 21184 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 11 ms 21336 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 Correct 791 ms 126644 KB Output is correct
3 Correct 888 ms 125932 KB Output is correct
4 Correct 1059 ms 134564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 791 ms 126644 KB Output is correct
3 Correct 888 ms 125932 KB Output is correct
4 Correct 1059 ms 134564 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1621 ms 149572 KB Output is correct
7 Incorrect 1140 ms 113612 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 791 ms 126644 KB Output is correct
3 Correct 888 ms 125932 KB Output is correct
4 Correct 1059 ms 134564 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Runtime error 12 ms 21340 KB Execution killed with signal 11
7 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 21424 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 21364 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -