Submission #962118

# Submission time Handle Problem Language Result Execution time Memory
962118 2024-04-13T07:12:12 Z Amr Strange Device (APIO19_strange_device) C++17
15 / 100
1731 ms 350272 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define S second
#define F first
#define all(x) (x).begin(),(x).end()
#define sz size()
#define Yes cout << "YES" << endl
#define No cout << "NO" << endl
#define pb(x) push_back(x);
#define endl '\n'
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int N=1e7;
ll INF=INT_MAX,mod=1e9+7;
int TT=1;
ll power(ll x, unsigned int y)
{
    ll res = 1;
    x = x; // % mod;
    if (x == 0) return 0;
    while (y > 0)
    {
        if (y & 1) res = (res*x)  ; // % mod;
        y = y>>1;
        x = (x*x) ; // % mod;
    }
    return res;
}
typedef unsigned long long ull;
ll lo(ll x)
{
    ll cnt = 0;
    while(x) cnt++,x/=10;
    return cnt-1;
}
ll f(ll x, ll y)
{
    ll m = (x/power(10,lo(x)))*(y/power(10,lo(y)));
    return (lo(x)+lo(y)+lo(m)>=19||(x*y)>1e18);
}
ll k = 1;
ll seg[N];
bool qu[N];
int L[N],R[N];
ll siz = 1e18;
void nn(ll x)
{
    L[x] = k++;
    L[k-1] = -1, R[k-1] = -1;
    R[x] = k++;
    L[k-1] = -1, R[k-1] = -1;
}
ll get(ll l ,ll r, ll x = 0, ll lx = 0, ll rx = siz)
{
    if(lx>=r||rx<=l) return 0;
    if(lx>=l&&rx<=r)
    {
        return seg[x];
    }
    ll mid = (lx+rx)/2;
    if(L[x]==-1) nn(x);
    ll s1 = get(l,r,L[x],lx,mid);
    ll s2 = get(l,r,R[x],mid,rx);
    return max(s1+s2,qu[x]*(min(rx,r)-max(lx,l)));
}
void update(ll l , ll r, ll x = 0, ll lx = 0, ll rx = siz)
{
    if(lx>=r||rx<=l) return;

    if(lx>=l&&rx<=r)
    {
        qu[x] = 1;
        seg[x] = (rx-lx);
        return;
    }
    ll mid = (lx+rx)/2;
    if(L[x]==-1) nn(x);
    update(l,r,L[x],lx,mid);
    update(l,r,R[x],mid,rx);
    //cout << lx << " " << rx << " ";
    seg[x] = max(seg[L[x]]+seg[R[x]],qu[x]*(rx-lx));
   //cout << x << seg[x] << qu[x] << endl;
}
void solve()
{
    L[0] = -1, R[0] = -1;
    ll n;
    ull a , b;
    cin >> n >> a >> b;
    ll mgcd = __gcd(a,b+1);
    a/=mgcd;
    ull cntans = 0;

    if(f(a,b))
    {
        for(int i = 1; i <= n; i++)
        {
        ull l , r; cin >> l >> r;
        cntans+=(r-l+1);
        }
        cout << cntans << endl;
        return;
    }
    a*=b;
    ull ab = a;
    //cout << ab << endl;

    ll ans = 0;
    for(int i = 1; i <= n; i++)
    {
        ull l , r; cin >> l >> r;
        //cout << min(a,r-l+1) << endl;
        l--,r--;
        if(r>=l+ab) r = l+ab-1;

        if(l%ab<=r%ab)
        {

            ans+=r-l+1-get(l%ab,r%ab+1);
            update(l%ab,r%ab+1);
        }
        else
        {

            ans+=r%ab+1-get(0,r%ab+1);
            ans+=ab-l%ab-get(l%ab,ab);
            update(0,r%ab+1);
            update(l%ab,ab);
        }
        //cout << 'h' << endl;
    }
    cout << ans << endl;
}
int main(){
    //freopen("friday.in","r",stdin);
    //freopen("friday.out","w",stdout);
    fast;
    while(TT--)
        solve();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 12 ms 7516 KB Output is correct
3 Correct 22 ms 8024 KB Output is correct
4 Correct 1 ms 2512 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2516 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2648 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 18 ms 7684 KB Output is correct
17 Correct 110 ms 12256 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 2 ms 4700 KB Output is correct
3 Correct 4 ms 4896 KB Output is correct
4 Correct 2 ms 4700 KB Output is correct
5 Incorrect 1731 ms 27512 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1128 ms 38608 KB Output is correct
3 Runtime error 807 ms 350272 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1128 ms 38608 KB Output is correct
3 Runtime error 807 ms 350272 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1128 ms 38608 KB Output is correct
3 Runtime error 807 ms 350272 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 143 ms 26832 KB Output is correct
3 Correct 209 ms 54740 KB Output is correct
4 Runtime error 727 ms 347756 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 12 ms 7516 KB Output is correct
3 Correct 22 ms 8024 KB Output is correct
4 Correct 1 ms 2512 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2516 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2648 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 18 ms 7684 KB Output is correct
17 Correct 110 ms 12256 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 2 ms 4700 KB Output is correct
26 Correct 4 ms 4896 KB Output is correct
27 Correct 2 ms 4700 KB Output is correct
28 Incorrect 1731 ms 27512 KB Output isn't correct
29 Halted 0 ms 0 KB -