Submission #440372

# Submission time Handle Problem Language Result Execution time Memory
440372 2021-07-02T07:58:43 Z KULIKOLD Strange Device (APIO19_strange_device) C++17
0 / 100
1 ms 204 KB
//#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
const int DIM = 1E6+7;
pair<ll,ll> M[DIM];
const ll MAXN = 2E18;
ll mult(ll a,ll b){
    ll mult = b;
    b = 0;
    while(a){
        if (a&1)
            b = min(b+mult,MAXN);
        mult = min(MAXN,mult*2);
        a/=2;
    }
    return b;
}
int solve(){
    ll n,A,B;
    cin>>n>>A>>B;
    for(int i = 1;i<=n;++i){
        cin>>M[i].first>>M[i].second;
    }
    if (B%A!=A-1)
        B = mult(A,B);
    vector<pair<ll,ll> > V;
    ll cnt = 0,sum = 0;
    for(int i = 1;i<=n;++i){
        sum+=M[i].second-M[i].first+1;
        ll start = M[i].first%B;
        ll fin = B-1;
        if (fin-start>M[i].second-M[i].first){
            V.push_back({M[i].first%B,1});
            V.push_back({M[i].second%B+1,-1});
            continue;
        }
        V.push_back({start,1});
        V.push_back({fin+1,-1});
        M[i].first+=fin-start+1;
        fin = M[i].second%B;
        start = 0;
        if (fin-start>M[i].second-M[i].first){
            V.push_back({M[i].first%B,1});
            V.push_back({M[i].second%B+1,-1});
            continue;
        }
        V.push_back({start,1});
        V.push_back({fin+1,-1});
        M[i].second-=fin-start+1;
        cnt+=(M[i].second-M[i].first)/B;
    }
    sort(V.begin(),V.end());
    ll last = 0,res = 0;
    for(int i = 0;i<V.size();++i){
        res+=(V[i].first-last)*max(0ll,cnt-1);
        last = V[i].first;
        int cur = V[i].first;
        cnt+=V[i].second;
        while(i+1<V.size() && V[i+1].first==cur){
            cnt+=V[++i].second;
        }
    }
    res+=(B-last)*cnt;
    cout<<sum-res<<endl;

    return 1;
}
int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    assert(solve());
    return 0;
}

Compilation message

strange_device.cpp: In function 'int solve()':
strange_device.cpp:56:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |     for(int i = 0;i<V.size();++i){
      |                   ~^~~~~~~~~
strange_device.cpp:61:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |         while(i+1<V.size() && V[i+1].first==cur){
      |               ~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -