Submission #557543

# Submission time Handle Problem Language Result Execution time Memory
557543 2022-05-05T12:51:20 Z Mounir Inside information (BOI21_servers) C++14
0 / 100
217 ms 788 KB
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define pb push_back
#define pii pair<int, int>
#define chmin(x, v) x = min(x, v)
#define chmax(x, v) x = max(x, v)
#define print(x) cout << #x << " est " << x << endl;
#define x first
#define y second
#define int long long
using namespace std;
 
const int N = 2e5;
int deb[N], fin[N];
int sum[2 * N];
int getSum(int g, int d){
      if (d < g) return 0;
      if (g%2 == 1) return sum[g] + getSum(g + 1, d);
      if (d%2 == 0) return sum[d] + getSum(g, d - 1);
      return getSum(g/2, d/2);
}

void upd(int i, int d){
      for (int nod = i; nod > 0; nod /= 2)
            sum[nod] += d;
}

void changeEtat(int i, int d){
      upd(N + deb[i], d);
      upd(N + fin[i], -d);
}
 
signed main(){  
      int nServs, nReqs; cin >> nServs >> nReqs;
      for (int i = 1; i <= nServs; ++i){
            deb[i] = i, fin[i] = i + 1;
            changeEtat(i, 1);
      }
      nReqs += nServs - 1;
      while (nReqs--){
            char typeReq; cin >> typeReq;
            if (typeReq == 'S'){
                  int a, b; cin >> a >> b;
                  changeEtat(a, -1);
                  changeEtat(b, -1);
                  int d = min(deb[a], deb[b]), f = max(fin[a], fin[b]);
                  deb[a] = deb[b] = d;
                  fin[a] = fin[b] = f;
                  changeEtat(a, 1);
                  changeEtat(b, 1);
            }
            else if (typeReq == 'Q'){
                  int a, d; cin >> a >> d;
                  if (deb[a] <= d && d <= fin[a]) cout << "yes" << endl;
                  else cout << "no" << endl;
            }
            else {
                  int d; cin >> d;
                  cout << getSum(N, N + d) << endl;
            }
      }
      return 0;   
}
# Verdict Execution time Memory Grader output
1 Incorrect 209 ms 788 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 209 ms 788 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 197 ms 672 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 197 ms 672 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 217 ms 664 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 217 ms 664 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 196 ms 684 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 196 ms 684 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 213 ms 776 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 213 ms 776 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 204 ms 656 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 204 ms 656 KB Output isn't correct
2 Halted 0 ms 0 KB -