Submission #317318

# Submission time Handle Problem Language Result Execution time Memory
317318 2020-10-29T12:31:43 Z soroush The Potion of Great Power (CEOI20_potion) C++14
100 / 100
2428 ms 30200 KB
/*
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
//*/
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ll maxn  = 1e5 + 10;
const ll mod =1e9+7;
const ld PI = acos((ld)-1);
 
#define pb push_back
//#define endl '\n'
#define dokme(x) cout << x , exit(0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ms(x , y) memset(x , y , sizeof x);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}
 
int n , d, u , q;
int h[maxn];
 
vector < pii > query[maxn] , ans;
vector < int > adr[maxn];
vector < int > vec[2];
vector < int > adj[4*maxn];
int bz = 64;
bool mark[maxn];
set < int > st;
vector < int > fuck;
int cur = 0;
 
void build(int v){
    st.clear();
    int cnt = 0;
    for(int i = 0 ; i < int(query[v].size()) ; i ++){
        cnt++;
        mark[query[v][i].second] ^= 1;
        if(!mark[query[v][i].second])st.erase(query[v][i].second);
        else st.insert(query[v][i].second);
        if(cnt==bz){
            adr[v].pb(cur);
            adj[cur].resize(st.size());
            int i = 0;
            for(int x : st) adj[cur][i++] = x;
            cur++;
            cnt = 0;
        }
        else
            adr[v].pb(-1);
    }
    for(int i : st)mark[i] = 0;
}
 
int solve(){
    sort(vec[0].begin() , vec[0].end());
    sort(vec[1].begin() , vec[1].end());
    int mn = 1e9;
    int p1 = 0 , p2 = 0;
    while(p1 < vec[0].size() and p2 < vec[1].size()){
        mn = min(mn , abs(vec[0][p1] - vec[1][p2]));
        if(vec[0][p1] < vec[1][p2])
            p1 ++;
        else
            p2 ++;
    }
    return(mn);
}
 
void get(int v , int t , int ind = 0){
    vec[ind].clear();
    if(query[v].size() == 0) return;
    if(query[v][0].first > t) return;
    int l = 0 , r = query[v].size();
    while(r - l > 1){
        int mid = (l + r)/2;
        if(query[v][mid].first > t)
            r = mid;
        else
            l = mid;
    }
    fuck.clear();
    while(l >= 0 and adr[v][l] == -1){
        mark[query[v][l].second] ^= 1;
        fuck.pb(query[v][l].second);
        l --;
    }
    if(l >= 0 and adr[v][l] > -1){
        for(int i : adj[adr[v][l]]){
            mark[i] ^= 1;
            fuck.pb(i);
        }
    }
    for(int i : fuck)
        if(mark[i]) vec[ind].pb(h[i]) , mark[i] = 0;
}
 
void curseChanges(int U, int A[], int B[]){
  int a , b;
   u = U;
    for(int i = 1 ; i <= U ; i ++){
        a = A[i - 1];
      	b = B[i - 1];
        a ++ , b ++ ;
        query[a].pb({i , b});
        query[b].pb({i , a});
    }
  	for(int i = 1 ; i <= n ; i ++)
        build(i);
}
 
int question(int X, int Y, int V){
  int x ,y , v;
  	x = X;
  y = Y;
  v = V;
 		 x ++ , y ++ ;
        get(x , v);
        get(y , v , 1);
        return (solve());
}
 
void init(int N, int D , int H[]){    n = N , d = D;
  	for(int i = 1 ; i <= n ; i ++)
      	h[i] = H[i-1];

}

Compilation message

potion.cpp: In function 'int solve()':
potion.cpp:68:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |     while(p1 < vec[0].size() and p2 < vec[1].size()){
      |           ~~~^~~~~~~~~~~~~~~
potion.cpp:68:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |     while(p1 < vec[0].size() and p2 < vec[1].size()){
      |                                  ~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 14464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 14464 KB Output is correct
2 Correct 11 ms 14464 KB Output is correct
3 Correct 12 ms 14464 KB Output is correct
4 Correct 29 ms 15480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 246 ms 26488 KB Output is correct
2 Correct 248 ms 26360 KB Output is correct
3 Correct 205 ms 22264 KB Output is correct
4 Correct 1249 ms 25392 KB Output is correct
5 Correct 347 ms 23672 KB Output is correct
6 Correct 2428 ms 30200 KB Output is correct
7 Correct 491 ms 26872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 240 ms 26264 KB Output is correct
2 Correct 985 ms 28924 KB Output is correct
3 Correct 654 ms 28012 KB Output is correct
4 Correct 1018 ms 30120 KB Output is correct
5 Correct 294 ms 26488 KB Output is correct
6 Correct 1140 ms 30072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 15232 KB Output is correct
2 Correct 83 ms 14976 KB Output is correct
3 Correct 137 ms 14976 KB Output is correct
4 Correct 695 ms 15232 KB Output is correct
5 Correct 695 ms 15232 KB Output is correct
6 Correct 88 ms 14968 KB Output is correct
7 Correct 580 ms 15224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 14464 KB Output is correct
2 Correct 12 ms 14464 KB Output is correct
3 Correct 11 ms 14464 KB Output is correct
4 Correct 12 ms 14464 KB Output is correct
5 Correct 29 ms 15480 KB Output is correct
6 Correct 246 ms 26488 KB Output is correct
7 Correct 248 ms 26360 KB Output is correct
8 Correct 205 ms 22264 KB Output is correct
9 Correct 1249 ms 25392 KB Output is correct
10 Correct 347 ms 23672 KB Output is correct
11 Correct 2428 ms 30200 KB Output is correct
12 Correct 491 ms 26872 KB Output is correct
13 Correct 240 ms 26264 KB Output is correct
14 Correct 985 ms 28924 KB Output is correct
15 Correct 654 ms 28012 KB Output is correct
16 Correct 1018 ms 30120 KB Output is correct
17 Correct 294 ms 26488 KB Output is correct
18 Correct 1140 ms 30072 KB Output is correct
19 Correct 49 ms 15232 KB Output is correct
20 Correct 83 ms 14976 KB Output is correct
21 Correct 137 ms 14976 KB Output is correct
22 Correct 695 ms 15232 KB Output is correct
23 Correct 695 ms 15232 KB Output is correct
24 Correct 88 ms 14968 KB Output is correct
25 Correct 580 ms 15224 KB Output is correct
26 Correct 684 ms 25848 KB Output is correct
27 Correct 1119 ms 28036 KB Output is correct
28 Correct 1242 ms 28172 KB Output is correct
29 Correct 1063 ms 25464 KB Output is correct
30 Correct 2343 ms 30200 KB Output is correct
31 Correct 2095 ms 28988 KB Output is correct
32 Correct 2073 ms 30072 KB Output is correct