Submission #1043841

# Submission time Handle Problem Language Result Execution time Memory
1043841 2024-08-04T22:34:37 Z beaconmc The Potion of Great Power (CEOI20_potion) C++14
38 / 100
3000 ms 127792 KB
#include <bits/stdc++.h>
 
typedef int ll;
#define FOR(i,x,y) for(ll i=x; i<y; i++)
#define FORNEG(i,x,y) for(ll i=x; i>y; i--)
 
using namespace std;
 
 
 
vector<ll> h;
vector<ll> a;
vector<ll> b;

vector<vector<ll>> changes[100001];
vector<unordered_set<ll>> lotchange[100001];
 
void init(int N, int D, int H[]) {
    FOR(i,0,N) h.push_back(H[i]);
}
 
void curseChanges(int U, int A[], int B[]) {
    vector<unordered_set<ll>> tempedges;
    tempedges.resize(100001);
    FOR(i,0,U){



        if (tempedges[A[i]].find(B[i]) != tempedges[A[i]].end()){
            changes[A[i]].push_back({i, B[i]});
            tempedges[A[i]].erase(B[i]);
        }
        else{
            changes[A[i]].push_back({i, B[i]});
            tempedges[A[i]].insert(B[i]);
        }

        if (tempedges[B[i]].find(A[i]) != tempedges[B[i]].end()){
            changes[B[i]].push_back({i, A[i]});
            tempedges[B[i]].erase(A[i]);
        } 
        else{
            changes[B[i]].push_back({i, A[i]});
            tempedges[B[i]].insert(A[i]);
        }
        if ((changes[A[i]].size()-1)%50==0){
            lotchange[A[i]].push_back(tempedges[A[i]]);
        }
        if ((changes[B[i]].size()-1)%50==0){
            lotchange[B[i]].push_back(tempedges[B[i]]);
        }


    }
}
 
int mindiff(unordered_set<ll>&a, unordered_set<ll>&b){
 
    ll ans = 1000000000;
    vector<pair<ll,ll>> A,B;
 
    for (auto&i : a) A.push_back(make_pair(h[i], (ll)0));
    for (auto&i : b) A.push_back(make_pair(h[i], (ll) 1));
 
    sort(A.begin(), A.end());
    if (A.size()==0) return ans;
    FOR(i,0,A.size()-1){
        if (A[i].second != A[i+1].second) ans = min(ans, abs(A[i].first-A[i+1].first));
    }
 
    return ans;
}
 
int question(int x, int y, int v) {

    v--;
    ll ans = 1000000000;


    ll pos = upper_bound(changes[x].begin(), changes[x].end(), vector<ll>{v, 1000000000})-changes[x].begin();
    pos--;
    

    unordered_set<ll> X;
    if (pos >= 0){
        X=lotchange[x][pos/50];

        FOR(i, (pos/50)*50+1, pos+1){

            ll temp = changes[x][i][1];

            if (X.find(temp) != X.end()) X.erase(temp);
            else X.insert(temp);

        }
    }


    pos = upper_bound(changes[y].begin(), changes[y].end(), vector<ll>{v, 1000000000})-changes[y].begin();
    pos--;
    

    unordered_set<ll> Y;
    if (pos >= 0){
        Y=lotchange[y][pos/50];

        FOR(i, (pos/50)*50+1, pos+1){

            ll temp = changes[y][i][1];

            if (Y.find(temp) != Y.end()) Y.erase(temp);
            else Y.insert(temp);

        }
    }






    return mindiff(X,Y);
}













Compilation message

potion.cpp: In function 'int mindiff(std::unordered_set<int>&, std::unordered_set<int>&)':
potion.cpp:4:33: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define FOR(i,x,y) for(ll i=x; i<y; i++)
......
   67 |     FOR(i,0,A.size()-1){
      |         ~~~~~~~~~~~~~~           
potion.cpp:67:5: note: in expansion of macro 'FOR'
   67 |     FOR(i,0,A.size()-1){
      |     ^~~
potion.cpp: In function 'int question(int, int, int)':
potion.cpp:77:8: warning: unused variable 'ans' [-Wunused-variable]
   77 |     ll ans = 1000000000;
      |        ^~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 10584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 11096 KB Output is correct
2 Correct 4 ms 11096 KB Output is correct
3 Correct 4 ms 11096 KB Output is correct
4 Correct 10 ms 12108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 318 ms 82036 KB Output is correct
2 Correct 314 ms 82128 KB Output is correct
3 Correct 213 ms 40144 KB Output is correct
4 Correct 2621 ms 88588 KB Output is correct
5 Correct 728 ms 59960 KB Output is correct
6 Execution timed out 3048 ms 127792 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 320 ms 82128 KB Output is correct
2 Correct 2391 ms 114896 KB Output is correct
3 Correct 1965 ms 98340 KB Output is correct
4 Execution timed out 3089 ms 127440 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 36 ms 15192 KB Output is correct
2 Correct 118 ms 12376 KB Output is correct
3 Correct 187 ms 12376 KB Output is correct
4 Correct 1149 ms 15332 KB Output is correct
5 Correct 1160 ms 15704 KB Output is correct
6 Correct 129 ms 12888 KB Output is correct
7 Correct 827 ms 13400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 10584 KB Output is correct
2 Correct 4 ms 11096 KB Output is correct
3 Correct 4 ms 11096 KB Output is correct
4 Correct 4 ms 11096 KB Output is correct
5 Correct 10 ms 12108 KB Output is correct
6 Correct 318 ms 82036 KB Output is correct
7 Correct 314 ms 82128 KB Output is correct
8 Correct 213 ms 40144 KB Output is correct
9 Correct 2621 ms 88588 KB Output is correct
10 Correct 728 ms 59960 KB Output is correct
11 Execution timed out 3048 ms 127792 KB Time limit exceeded
12 Halted 0 ms 0 KB -