Submission #132924

# Submission time Handle Problem Language Result Execution time Memory
132924 2019-07-20T00:39:00 Z 12tqian Strange Device (APIO19_strange_device) C++14
5 / 100
652 ms 17844 KB
#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

const double PI = 4 * atan(1);

#define sz(x) (int)(x).size()
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair <int, int>
#define vi vector<int>
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define vpi vector<pair<int, int>>
#define vpd vector<pair<double, double>>
#define pd pair<double, double>

#define f0r(i,a) for(int i=0;i<a;i++)
#define f1r(i,a,b) for(int i=a;i<b;i++)
#define trav(a, x) for (auto& a : x)

void fast_io(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
void io(string taskname){
    string fin = taskname + ".in";
    string fout = taskname + ".out";
    const char* FIN = fin.c_str();
    const char* FOUT = fout.c_str();
    freopen(FIN, "r", stdin);
    freopen(FOUT, "w", stdout);
    fast_io();
}
const long long MOD = 1000003;
long long modInverse(long long b){
    long long ex = MOD - 2;
    if (b==1){
        return 1;
    }
    long long r = 1;
    while (ex ){
        if (ex&1){
            r=(r * b)%MOD;
        }
        ex = ex >> 1;
        b = (b * b)%MOD;
    }
    return r;
}
vector<pair<ll, ll>> intervals;
int main(){
    fast_io();
    ll n, a, b;
    cin >> n >> a >> b;
    ll tmp = a/__gcd(a, b+1);
    ll mod = -1;
    double verify = log10(a) + log10(b)-log10(__gcd(a, b)) + log10(tmp);
    if(verify<= 18){
        mod = a/__gcd(a, b)* b* tmp;
    }
    if(mod == -1){
        ll ans = 0;
        f0r(i, n){
            ll l, r;
            cin >> l >> r;
            ans += (r-l + 1);
        }
        cout << ans << endl;
        return 0;
    }
    f0r(i, n){
        ll l, r;
        cin >> l >> r;
        if(r-l>= mod-1){
            cout << mod << endl;
            return 0;
        }
        l%= mod;
        r%= mod;
        if(l>r){
            intervals.eb(mp(l, mod-1));
            intervals.eb(mp(0, r));
          //  cout << "here" << endl;
        }
        else{
            intervals.eb(mp(l, r));
        }
    }
    sort(all(intervals));
    ll ans = 0;
    f0r(i, sz(intervals)){
       // cout << intervals[i].f << " df " << intervals[i].s << endl;
        if(i == 0){
            ans += (intervals[i].s - intervals[i].f + 1);
        }
        else{
            ll l = intervals[i].f;
            ll r = intervals[i].s;
            ll lo = intervals[i-1].f;
            ll hi = intervals[i-1].s;
            if(r<= hi) continue;
            if(l>hi){
                ans += (r - l + 1);
            }
            else{
                ans += (r - hi);
            }
        }

    }
    cout << ans << endl;
    return 0;
}

Compilation message

strange_device.cpp:1:0: warning: ignoring #pragma comment  [-Wunknown-pragmas]
 #pragma comment(linker, "/stack:200000000")
 
strange_device.cpp: In function 'int main()':
strange_device.cpp:116:16: warning: unused variable 'lo' [-Wunused-variable]
             ll lo = intervals[i-1].f;
                ^~
strange_device.cpp: In function 'void io(std::__cxx11::string)':
strange_device.cpp:47:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen(FIN, "r", stdin);
     ~~~~~~~^~~~~~~~~~~~~~~~~
strange_device.cpp:48:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen(FOUT, "w", stdout);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 8 ms 1016 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 1 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 376 KB Output is correct
2 Incorrect 3 ms 380 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 416 KB Output is correct
2 Incorrect 652 ms 17844 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 416 KB Output is correct
2 Incorrect 652 ms 17844 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 416 KB Output is correct
2 Incorrect 652 ms 17844 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 67 ms 3232 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 8 ms 1016 KB Output isn't correct
3 Halted 0 ms 0 KB -