Submission #669344

# Submission time Handle Problem Language Result Execution time Memory
669344 2022-12-06T09:27:10 Z berr The Potion of Great Power (CEOI20_potion) C++17
0 / 100
588 ms 49736 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+30;
bitset<504> sts[N];
vector<array<int, 2>> adj[N];
vector<int> h, st[N];
map<array<int, 2>, int> mp;
bitset<504> s;



void init(int n, int d, int H[]){

    for(int i=0; i<n; i++){
        sts[i]=s;
        st[i].push_back(-1);
    }

    for(int i=0; i<n; i++){
        h.push_back(H[i]);
    }


}

void curseChanges(int u, int a[], int b[]){
    for(int i=0; i<u; i++){
        adj[a[i]].push_back({h[b[i]], b[i]});
        adj[b[i]].push_back({h[a[i]], a[i]});
    }

    for(int i=0; i<N; i++){
        sort(adj[i].begin(), adj[i].end());
    }


   for(int i=0; i<N; i++){
        for(int l=0; l<adj[i].size(); l++){
            mp[{i, adj[i][l][1]}]=l;
        }
    }

    for(int i=0; i<u; i++){
        int x=a[i], y=b[i];

        bitset ss=sts[x];
        
        int pos=mp[{x, y}];
        if(ss[pos]==1) ss[pos]=0;
        else ss[pos]=1; 

        sts[x]=ss;
        st[x].push_back(i);


        ss=sts[y];
        pos=mp[{y, x}];

        if(ss[pos]==1) ss[pos]=0;
        else ss[pos]=1; 

        sts[y]=ss;
        st[y].push_back(i);

    }
}


int question(int x, int y, int v){

  
    bitset sx = sts[x], sy=sts[y];



    if(!sx.count() || !sy.count()) return 1e9;

    int lx=0, ly=0;
      
    while(lx<sx.size() && sx[lx]==0) lx++;
    while(ly<sy.size() && sy[ly]==0) ly++;

    int ans=1e9;

    while(lx<sx.size() && ly < sy.size()){
        int vx=adj[x][lx][0];
        int vy=adj[y][ly][0];

        ans=min(ans, abs(vx-vy));

        if(vx < vy){
            lx ++;
            while(lx<sx.size() && sx[lx]==0) lx++;
        }
        else if(vx > vy){
            ly ++;
            while(ly<sy.size() && sy[ly]==0) ly++;
        }
        else{
            break;
        }
    }

    return ans;

}/*
int main() {
  int N, D, U, Q;
  std::ios::sync_with_stdio(false); std::cin.tie(NULL);
  std::cin >> N >> D >> U >> Q;

  int *F = new int[N];
  for (int i=0; i<N; i++)
    std::cin >> F[i];
  init(N, D, F);

  int *A = new int[U], *B = new int[U];
  for (int i=0; i<U; i++) {
    std::cin >> A[i] >> B[i];
  }
  curseChanges(U, A, B);

  bool correct = true;
  for (int i=0; i<Q; i++) {
    int X,Y,V,CorrectAnswer;
    std::cin >> X >> Y >> V >> CorrectAnswer;
    int YourAnswer = question(X,Y,V);
    if (YourAnswer != CorrectAnswer) {
      std::cout << "WA! Question: " << i
		<< " (X=" << X << ", Y=" << Y << ", V=" << V << ") "
		<<  "Your answer: " << YourAnswer
                << " Correct Answer: " << CorrectAnswer << std::endl;
      correct = false;
    } else {
      std::cerr << YourAnswer << " - OK" << std::endl;
    }
  }

  if (correct) {
    std::cout << "Correct." << std::endl;
  } else std::cout << "Incorrect." << std::endl;
  return 0;
}
*/

Compilation message

potion.cpp: In function 'void curseChanges(int, int*, int*)':
potion.cpp:38:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |         for(int l=0; l<adj[i].size(); l++){
      |                      ~^~~~~~~~~~~~~~
potion.cpp: In function 'int question(int, int, int)':
potion.cpp:80:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::size_t' {aka 'long unsigned int'} [-Wsign-compare]
   80 |     while(lx<sx.size() && sx[lx]==0) lx++;
      |           ~~^~~~~~~~~~
potion.cpp:81:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::size_t' {aka 'long unsigned int'} [-Wsign-compare]
   81 |     while(ly<sy.size() && sy[ly]==0) ly++;
      |           ~~^~~~~~~~~~
potion.cpp:85:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::size_t' {aka 'long unsigned int'} [-Wsign-compare]
   85 |     while(lx<sx.size() && ly < sy.size()){
      |           ~~^~~~~~~~~~
potion.cpp:85:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::size_t' {aka 'long unsigned int'} [-Wsign-compare]
   85 |     while(lx<sx.size() && ly < sy.size()){
      |                           ~~~^~~~~~~~~~~
potion.cpp:93:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::size_t' {aka 'long unsigned int'} [-Wsign-compare]
   93 |             while(lx<sx.size() && sx[lx]==0) lx++;
      |                   ~~^~~~~~~~~~
potion.cpp:97:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::size_t' {aka 'long unsigned int'} [-Wsign-compare]
   97 |             while(ly<sy.size() && sy[ly]==0) ly++;
      |                   ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4944 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 5200 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 570 ms 49664 KB Output is correct
2 Correct 588 ms 49588 KB Output is correct
3 Runtime error 147 ms 44632 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 509 ms 49736 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 7728 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4944 KB Incorrect
2 Halted 0 ms 0 KB -