Submission #932778

# Submission time Handle Problem Language Result Execution time Memory
932778 2024-02-24T07:46:53 Z 12345678 Strange Device (APIO19_strange_device) C++17
10 / 100
597 ms 78836 KB
#include <bits/stdc++.h>

using namespace std;

#define ll unsigned long long

const int nx=1e6+5;
ll n, a, b, l[nx], r[nx], sm, p, mx, res;
set<pair<ll, ll>> s;

void add_range(ll x, ll y)
{
    x=x%p;
    y=y%p;
    if (y<x) y+=p;
    s.insert({x, min(p-1, y)});
    if (y>=p) s.insert({0, y-p});
}

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n>>a>>b;
    p=a*b;
    for (int i=1; i<=n; i++) cin>>l[i]>>r[i], mx=max(mx, r[i]-l[i]+1), sm+=(r[i]-l[i]+1);
    if (a>=(LLONG_MAX-1)/b+1) return cout<<sm, 0;
    if (mx>=p) return cout<<p, 0;
    for (int i=1; i<=n; i++) add_range(l[i], r[i]);
    //for (auto [x, y]:s) cout<<"val "<<x<<' '<<y<<'\n';
    for (auto itr=s.begin(); itr!=s.end()&&next(itr)!=s.end();)
    {
        auto itr2=next(itr);
        pair<ll, ll> nw;
        if (itr2->first>itr->second+1) itr=itr2;
        else nw={itr->first, max(itr->second, itr2->second)}, s.erase(itr), s.erase(itr2), s.insert(nw), itr=s.find(nw);
    }
    for (auto [x, y]:s) res+=y-x+1;
    cout<<res;
}

/*
3 5 10
1 20
50 68
89 98

*/

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:25:20: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
   25 |     for (int i=1; i<=n; i++) cin>>l[i]>>r[i], mx=max(mx, r[i]-l[i]+1), sm+=(r[i]-l[i]+1);
      |                   ~^~~
strange_device.cpp:28:20: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
   28 |     for (int i=1; i<=n; i++) add_range(l[i], r[i]);
      |                   ~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 5 ms 3160 KB Output is correct
3 Correct 5 ms 3160 KB Output is correct
4 Incorrect 1 ms 2396 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 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 0 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 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 184 ms 16000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 493 ms 78704 KB Output is correct
3 Incorrect 534 ms 78716 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 493 ms 78704 KB Output is correct
3 Incorrect 534 ms 78716 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 493 ms 78704 KB Output is correct
3 Incorrect 534 ms 78716 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 53 ms 12884 KB Output is correct
3 Correct 55 ms 13036 KB Output is correct
4 Correct 551 ms 78672 KB Output is correct
5 Correct 52 ms 12884 KB Output is correct
6 Correct 64 ms 12880 KB Output is correct
7 Correct 51 ms 13044 KB Output is correct
8 Correct 54 ms 13036 KB Output is correct
9 Correct 50 ms 13036 KB Output is correct
10 Correct 47 ms 13168 KB Output is correct
11 Correct 47 ms 12880 KB Output is correct
12 Correct 47 ms 12920 KB Output is correct
13 Correct 52 ms 12936 KB Output is correct
14 Correct 597 ms 78836 KB Output is correct
15 Incorrect 51 ms 12892 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 5 ms 3160 KB Output is correct
3 Correct 5 ms 3160 KB Output is correct
4 Incorrect 1 ms 2396 KB Output isn't correct
5 Halted 0 ms 0 KB -