Submission #724608

# Submission time Handle Problem Language Result Execution time Memory
724608 2023-04-15T16:28:46 Z n0sk1ll Strange Device (APIO19_strange_device) C++17
65 / 100
2066 ms 381612 KB
#include <bits/stdc++.h>

#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0)
#define mp make_pair
#define xx first
#define yy second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(x) x.begin(),x.end()
#define ff(i,a,b) for (int i = a; i < b; i++)
#define fff(i,a,b) for (int i = a; i <= b; i++)
#define bff(i,a,b) for (int i = b-1; i >= a; i--)
#define bfff(i,a,b) for (int i = b; i >= a; i--)

using namespace std;
long double typedef ld;
unsigned int typedef ui;
long long int typedef li;
pair<int,int> typedef pii;
pair<li,li> typedef pli;
pair<ld,ld> typedef pld;
vector<vector<int>> typedef graph;
unsigned long long int typedef ull;
//const int mod = 998244353;
const int mod = 1000000007;







//Note to self: Check for overflow

map<li,vector<pli>> segs;
set<li> kords;
map<li,li> cisti;


int main()
{
    FAST;

    int n; cin>>n;
    li A,B; cin>>A>>B;

    li d=__gcd(A,B+1);
    A/=d;

    vector<pli> ulaz;
    while (n--)
    {
        li l,r; cin>>l>>r;
        if (A<LONG_LONG_MAX/B) l%=(A*B),r%=(A*B);
        if (l>r) ulaz.pb({0,r}),ulaz.pb({l,A*B-1});
        else ulaz.pb({l,r});
    }

    for (auto [l,r] : ulaz)
    {
        if (r/A == l/A) segs[l/A].pb({l%A,r%A}),kords.insert(l/A);
        else
        {
            segs[l/A].pb({l%A,A-1});
            segs[r/A].pb({0,r%A});
            cisti[l/A+1]++;
            cisti[r/A]--;
            kords.insert(l/A);
            kords.insert(l/A+1);
            kords.insert(r/A);
        }
    }

    li ans=0;

    li kolkoclear=0;
    li majmuncina=-1;
    for (auto x : kords)
    {
        bool staromeso=false;
        if (kolkoclear==0) staromeso=true;
        kolkoclear+=cisti[x]; //cout<<x<<": "<<cisti[x]<<endl;
        if (kolkoclear>0 && staromeso) majmuncina=x;

        //cout<<"marmun "<<kolkoclear<<endl;

        if (kolkoclear==0 && majmuncina!=-1) ans+=(x-majmuncina)*A,majmuncina=-1;
        if (kolkoclear==0)
        {
            vector<pair<li,li>> lensi;
            for (auto it : segs[x]) lensi.pb({it.xx,1}),lensi.pb({it.yy+1,-1});
            sort(all(lensi));

            li preth=-1;
            li kolkocur=0;
            for (auto y : lensi)
            {
                if (preth!=-1 && kolkocur) ans+=y.xx-preth;
                preth=y.xx; kolkocur+=y.yy;
            }
        }
    }

    cout<<ans<<"\n";
}

//Note to self: Check for overflow
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 6 ms 1100 KB Output is correct
3 Correct 6 ms 1112 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 312 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 6 ms 1060 KB Output is correct
17 Correct 47 ms 7472 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 724 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 557 ms 105076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 579 ms 75164 KB Output is correct
3 Correct 581 ms 75136 KB Output is correct
4 Correct 559 ms 85048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 579 ms 75164 KB Output is correct
3 Correct 581 ms 75136 KB Output is correct
4 Correct 559 ms 85048 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 610 ms 108356 KB Output is correct
7 Correct 648 ms 101368 KB Output is correct
8 Correct 602 ms 90452 KB Output is correct
9 Correct 723 ms 103424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 579 ms 75164 KB Output is correct
3 Correct 581 ms 75136 KB Output is correct
4 Correct 559 ms 85048 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 57 ms 8072 KB Output is correct
7 Correct 61 ms 8936 KB Output is correct
8 Correct 60 ms 8912 KB Output is correct
9 Correct 55 ms 9188 KB Output is correct
10 Correct 52 ms 7440 KB Output is correct
11 Correct 56 ms 7464 KB Output is correct
12 Correct 50 ms 7360 KB Output is correct
13 Correct 46 ms 7452 KB Output is correct
14 Correct 189 ms 41016 KB Output is correct
15 Correct 51 ms 8132 KB Output is correct
16 Correct 60 ms 9276 KB Output is correct
17 Correct 211 ms 40004 KB Output is correct
18 Correct 510 ms 53472 KB Output is correct
19 Correct 457 ms 53960 KB Output is correct
20 Correct 463 ms 54624 KB Output is correct
21 Correct 52 ms 7620 KB Output is correct
22 Correct 46 ms 7616 KB Output is correct
23 Correct 214 ms 58876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 54 ms 8552 KB Output is correct
3 Correct 78 ms 12484 KB Output is correct
4 Correct 834 ms 97524 KB Output is correct
5 Correct 247 ms 40000 KB Output is correct
6 Correct 251 ms 40072 KB Output is correct
7 Correct 244 ms 40024 KB Output is correct
8 Correct 49 ms 7604 KB Output is correct
9 Correct 98 ms 16312 KB Output is correct
10 Correct 188 ms 40092 KB Output is correct
11 Correct 184 ms 40248 KB Output is correct
12 Correct 182 ms 40184 KB Output is correct
13 Correct 47 ms 8112 KB Output is correct
14 Correct 496 ms 44364 KB Output is correct
15 Correct 77 ms 13968 KB Output is correct
16 Correct 2066 ms 381612 KB Output is correct
17 Correct 480 ms 54840 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 6 ms 1100 KB Output is correct
3 Correct 6 ms 1112 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 312 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 6 ms 1060 KB Output is correct
17 Correct 47 ms 7472 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Incorrect 1 ms 212 KB Output isn't correct
21 Halted 0 ms 0 KB -