Submission #683669

# Submission time Handle Problem Language Result Execution time Memory
683669 2023-01-19T05:14:39 Z Nursik Strange Device (APIO19_strange_device) C++17
65 / 100
541 ms 69068 KB
#include <stdio.h>
 
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
 
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ld long double
#define bug cout << "bug\n";

const ll maxn = 1e6 + 5, maxm = 2e2 + 1;
const ll mod = 1e9 + 7, inf = 1e9, block = 550, hb = 126067, base = 1000050017,
         biginf = 5e18;
const ld eps = 1e-15;
using namespace std;

int n;
ll a, b;
ll l[maxn], r[maxn];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n >> a >> b;
    ll p = a * b / gcd(a, b + 1);
    vector<pair<ll, ll>> v;
    for (int i = 1; i <= n; ++i){
        cin >> l[i] >> r[i];
        ll x = l[i] % p;
        ll y = r[i] % p;
        if (x <= y){
            v.pb(mp(x, y));
        }
        else{
            v.pb(mp(x, p - 1));
            v.pb(mp(0, y));
        }
    }
    sort(v.begin(), v.end());
    ll ans = 0, nxt = -1;
    for (auto it : v){
        ll lf = it.f, rg = it.s;
        if (nxt < lf){
            ans += rg - lf + 1;
            nxt = rg;
        }
        else if (nxt <= rg){
            ans += rg - nxt;
            nxt = rg;
        }
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 5 ms 900 KB Output is correct
3 Correct 5 ms 856 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 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 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 5 ms 980 KB Output is correct
17 Correct 46 ms 3812 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 0 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 390 ms 52208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 430 ms 32308 KB Output is correct
3 Correct 490 ms 68936 KB Output is correct
4 Correct 465 ms 68852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 430 ms 32308 KB Output is correct
3 Correct 490 ms 68936 KB Output is correct
4 Correct 465 ms 68852 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 443 ms 68968 KB Output is correct
7 Correct 531 ms 68904 KB Output is correct
8 Correct 475 ms 68888 KB Output is correct
9 Correct 484 ms 68864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 430 ms 32308 KB Output is correct
3 Correct 490 ms 68936 KB Output is correct
4 Correct 465 ms 68852 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 46 ms 7228 KB Output is correct
7 Correct 44 ms 7228 KB Output is correct
8 Correct 40 ms 7296 KB Output is correct
9 Correct 48 ms 7248 KB Output is correct
10 Correct 43 ms 7200 KB Output is correct
11 Correct 53 ms 7200 KB Output is correct
12 Correct 53 ms 7280 KB Output is correct
13 Correct 44 ms 7232 KB Output is correct
14 Correct 45 ms 7212 KB Output is correct
15 Correct 44 ms 7272 KB Output is correct
16 Correct 56 ms 7236 KB Output is correct
17 Correct 43 ms 7260 KB Output is correct
18 Correct 466 ms 68796 KB Output is correct
19 Correct 482 ms 68852 KB Output is correct
20 Correct 541 ms 68792 KB Output is correct
21 Correct 46 ms 7220 KB Output is correct
22 Correct 55 ms 7280 KB Output is correct
23 Correct 128 ms 23704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 45 ms 7184 KB Output is correct
3 Correct 44 ms 7188 KB Output is correct
4 Correct 513 ms 64484 KB Output is correct
5 Correct 43 ms 7220 KB Output is correct
6 Correct 48 ms 7200 KB Output is correct
7 Correct 44 ms 7216 KB Output is correct
8 Correct 44 ms 7300 KB Output is correct
9 Correct 42 ms 7316 KB Output is correct
10 Correct 55 ms 7276 KB Output is correct
11 Correct 45 ms 7252 KB Output is correct
12 Correct 41 ms 7224 KB Output is correct
13 Correct 48 ms 7224 KB Output is correct
14 Correct 481 ms 68912 KB Output is correct
15 Correct 50 ms 7208 KB Output is correct
16 Correct 399 ms 69068 KB Output is correct
17 Correct 401 ms 68800 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 Correct 5 ms 900 KB Output is correct
3 Correct 5 ms 856 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 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 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 5 ms 980 KB Output is correct
17 Correct 46 ms 3812 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Incorrect 0 ms 340 KB Output isn't correct
21 Halted 0 ms 0 KB -