Submission #363988

# Submission time Handle Problem Language Result Execution time Memory
363988 2021-02-07T20:54:04 Z erfanmir Strange Device (APIO19_strange_device) C++17
25 / 100
847 ms 54404 KB
// In the name of god

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds; 

template < class T > using ordered_set = tree < T , null_type , less < T > , rb_tree_tag , tree_order_statistics_node_update >;
  
typedef long long                   ll;
typedef long double                 ld;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
#define all(x)                      (x).begin(),(x).end()
#define lc(x)                       (x) << 1
#define rc(x)                       (x) << 1 | 1
#define F                           first
#define S                           second
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define mp                          make_pair
ll poww(ll a, ll b, ll md) {
    ll ans = 1;
    for(; b; b >>= 1, a = a * a % md){
        if(b & 1){
            ans = ans * a % md;
        }
    }
    return ans % md;
}

const int MAXN = 1e6 + 10;
const int MAXLG = 18;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const ll INF = 1e18 + 10;

int n, val[MAXN];
ll A, B, ans, l[MAXN], r[MAXN];
vector<ll> vec;
vector<pll> seg;

int main()
{
    scanf("%d %lld %lld", &n, &A, &B);
    for(int i = 1; i <= n; i++){
        scanf("%lld %lld", l + i, r + i);
    }
    ll x = A / __gcd(A, B + 1);
    if(x > INF / B){
        for(int i = 1; i <= n; i++){
            ans += r[i] - l[i] + 1;
        }
        printf("%lld\n", ans);
        return 0;
    }
    x *= B;
    vec.push_back(0);
    vec.push_back(x);
    for(int i = 1; i <= n; i++){
        if(r[i] - l[i] + 1 >= x){
            printf("%lld\n", x);
            return 0;
        }
        ll L = l[i], R = r[i];
        L %= x;
        R %= x;
        vec.push_back(L);
        vec.push_back(R + 1);
        if(L > R){
            seg.push_back(mp(L, x - 1));
            seg.push_back(mp(0, R));
        }
        else{
            seg.push_back(mp(L, R));
        }
    }
    sort(all(vec));
    vec.erase(unique(all(vec)), vec.end());
    for(auto v : seg){
        int ind1;
        int ind2;
        ind1 = lower_bound(all(vec), v.F) - vec.begin();
        ind2 = lower_bound(all(vec), v.S + 1) - vec.begin();
        val[ind1]++;
        val[ind2]--;
    }
    for(int i = 1; i < (int)vec.size(); i++){
        val[i] += val[i - 1];
    }
    for(int i = 0; i < (int)vec.size() - 1; i++){
        if(val[i]){
            ans += vec[i + 1] - vec[i];
        }
    }
    printf("%lld\n", ans);
}

Compilation message

strange_device.cpp:3: warning: ignoring #pragma comment  [-Wunknown-pragmas]
    3 | #pragma comment(linker, "/stack:200000000")
      | 
strange_device.cpp: In function 'int main()':
strange_device.cpp:49:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   49 |     scanf("%d %lld %lld", &n, &A, &B);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:51:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   51 |         scanf("%lld %lld", l + i, r + i);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 8 ms 1388 KB Output is correct
3 Correct 8 ms 1388 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 7 ms 1388 KB Output is correct
17 Correct 77 ms 6744 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 2 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 419 ms 48660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 713 ms 52484 KB Output is correct
3 Correct 739 ms 52612 KB Output is correct
4 Correct 698 ms 53588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 713 ms 52484 KB Output is correct
3 Correct 739 ms 52612 KB Output is correct
4 Correct 698 ms 53588 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 673 ms 53764 KB Output is correct
7 Correct 687 ms 53508 KB Output is correct
8 Correct 707 ms 53632 KB Output is correct
9 Incorrect 772 ms 53788 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 713 ms 52484 KB Output is correct
3 Correct 739 ms 52612 KB Output is correct
4 Correct 698 ms 53588 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 80 ms 6712 KB Output is correct
7 Correct 73 ms 6736 KB Output is correct
8 Correct 67 ms 6696 KB Output is correct
9 Correct 72 ms 6736 KB Output is correct
10 Correct 70 ms 6736 KB Output is correct
11 Correct 71 ms 6736 KB Output is correct
12 Correct 67 ms 6736 KB Output is correct
13 Correct 76 ms 6736 KB Output is correct
14 Correct 69 ms 6736 KB Output is correct
15 Correct 74 ms 6736 KB Output is correct
16 Correct 76 ms 6864 KB Output is correct
17 Correct 89 ms 6736 KB Output is correct
18 Correct 718 ms 53596 KB Output is correct
19 Correct 735 ms 54404 KB Output is correct
20 Incorrect 769 ms 53508 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 76 ms 6736 KB Output is correct
3 Correct 76 ms 6736 KB Output is correct
4 Incorrect 847 ms 52244 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 8 ms 1388 KB Output is correct
3 Correct 8 ms 1388 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 7 ms 1388 KB Output is correct
17 Correct 77 ms 6744 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 2 ms 492 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 419 ms 48660 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 713 ms 52484 KB Output is correct
31 Correct 739 ms 52612 KB Output is correct
32 Correct 698 ms 53588 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 673 ms 53764 KB Output is correct
35 Correct 687 ms 53508 KB Output is correct
36 Correct 707 ms 53632 KB Output is correct
37 Incorrect 772 ms 53788 KB Output isn't correct