Submission #986634

# Submission time Handle Problem Language Result Execution time Memory
986634 2024-05-21T00:09:46 Z vjudge1 The Potion of Great Power (CEOI20_potion) C++17
35 / 100
3000 ms 217960 KB
#include<bits/stdc++.h>
using namespace std;
int SSZ=20;
vector<pair<int,int>>C[100100];
map<int,set<int>> temps[100100];
set<int>cur[100100];
int h[100100],ord[100100],rev[100100],CC;
void init(int N, int D, int H[]) {
    vector<int>v;
    for(int i=0;i<N;i++) h[i]=H[i],
        v.push_back(i),temps[i][-1];
    sort(v.begin(),v.end(),[](int a,int b){return h[a]<h[b];});
    for(int i=0;i<N;i++)
        rev[ord[v[i]]=i]=v[i];
}
void curseChanges(int U, int A[], int B[]) {
    for(int i=0;i<U;i++){
        A[i]=ord[A[i]];
        B[i]=ord[B[i]];
        if(cur[A[i]].count(B[i]))
            cur[A[i]].erase(B[i]),
            cur[B[i]].erase(A[i]);
        else cur[A[i]].insert(B[i]),
            cur[B[i]].insert(A[i]);
        C[A[i]].push_back({i,B[i]});
        C[B[i]].push_back({i,A[i]});
        if(C[A[i]].size()%SSZ==0)
            temps[A[i]][i]=cur[A[i]];
        if(C[B[i]].size()%SSZ==0)
            temps[B[i]][i]=cur[B[i]];
    }
    for(auto&i:cur)
        i.clear();
}
int calc(vector<int>A,vector<int>B){
    int l=0,r=0,ans=1e9;
    while(l<A.size()&&r<B.size()){
        ans=min(ans,abs(A[l]-B[r]));
        if(A[l]<B[r])l++;
        else r++;
    }
    return ans;
}
int question(int x, int y, int v) {
    x=ord[x],y=ord[y];
    vector<int>A,B;
    auto it=--temps[x].lower_bound(v);
    set<int>X=it->second;
    auto it2=lower_bound(C[x].begin(),C[x].end(),make_pair(it->first+1,0));
    for(int i=it2-C[x].begin();i<C[x].size()&&C[x][i].first<v;i++)
        if(X.count(C[x][i].second))
            X.erase(C[x][i].second);
        else X.insert(C[x][i].second);
    for(auto i:X)A.push_back(h[rev[i]]);
    it=--temps[y].upper_bound(v);
    X=it->second;
    it2=lower_bound(C[y].begin(),C[y].end(),make_pair(it->first+1,0));
    for(int i=it2-C[y].begin();i<C[y].size()&&C[y][i].first<v;i++)
        if(X.count(C[y][i].second))
            X.erase(C[y][i].second);
        else X.insert(C[y][i].second);
    for(auto i:X)B.push_back(h[rev[i]]);
    return calc(A,B);
}

Compilation message

potion.cpp: In function 'int calc(std::vector<int>, std::vector<int>)':
potion.cpp:37:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     while(l<A.size()&&r<B.size()){
      |           ~^~~~~~~~~
potion.cpp:37:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     while(l<A.size()&&r<B.size()){
      |                       ~^~~~~~~~~
potion.cpp: In function 'int question(int, int, int)':
potion.cpp:50:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |     for(int i=it2-C[x].begin();i<C[x].size()&&C[x][i].first<v;i++)
      |                                ~^~~~~~~~~~~~
potion.cpp:58:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |     for(int i=it2-C[y].begin();i<C[y].size()&&C[y][i].first<v;i++)
      |                                ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 12120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 12376 KB Output is correct
2 Correct 8 ms 12376 KB Output is correct
3 Correct 7 ms 12376 KB Output is correct
4 Correct 32 ms 23480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 331 ms 50004 KB Output is correct
2 Correct 321 ms 49788 KB Output is correct
3 Correct 259 ms 38740 KB Output is correct
4 Correct 1450 ms 147080 KB Output is correct
5 Correct 596 ms 59832 KB Output is correct
6 Execution timed out 3097 ms 204268 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 298 ms 49880 KB Output is correct
2 Correct 2311 ms 217960 KB Output is correct
3 Correct 1242 ms 120024 KB Output is correct
4 Correct 2589 ms 203428 KB Output is correct
5 Correct 550 ms 59648 KB Output is correct
6 Correct 2784 ms 204324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 14680 KB Output is correct
2 Incorrect 32 ms 14276 KB Incorrect
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 12120 KB Output is correct
2 Correct 7 ms 12376 KB Output is correct
3 Correct 8 ms 12376 KB Output is correct
4 Correct 7 ms 12376 KB Output is correct
5 Correct 32 ms 23480 KB Output is correct
6 Correct 331 ms 50004 KB Output is correct
7 Correct 321 ms 49788 KB Output is correct
8 Correct 259 ms 38740 KB Output is correct
9 Correct 1450 ms 147080 KB Output is correct
10 Correct 596 ms 59832 KB Output is correct
11 Execution timed out 3097 ms 204268 KB Time limit exceeded
12 Halted 0 ms 0 KB -