Submission #989045

# Submission time Handle Problem Language Result Execution time Memory
989045 2024-05-27T10:53:50 Z AdamGS Comparing Plants (IOI20_plants) C++17
44 / 100
238 ms 23028 KB
#include "plants.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=2e5+7, INF=1e9+7;
set<int>A, B;
pair<int,int>tr[4*LIM];
int lazy[4*LIM], T[LIM], n, k, N=1;
void spl(int v) {
  tr[2*v].st+=lazy[v];
  tr[2*v+1].st+=lazy[v];
  lazy[2*v]+=lazy[v];
  lazy[2*v+1]+=lazy[v];
  lazy[v]=0;
}
void upd(int v, int l, int r, int a, int b, int x) {
  if(r<a || b<l) return;
  if(a<=l && r<=b) {
    tr[v].st+=x;
    lazy[v]+=x;
    return;
  }
  if(lazy[v]) spl(v);
  int mid=(l+r)/2;
  upd(2*v, l, mid, a, b, x);
  upd(2*v+1, mid+1, r, a, b, x);
  tr[v]=min(tr[2*v], tr[2*v+1]);
}
pair<int,int>cnt(int v, int l, int r, int a, int b) {
  if(r<a || b<l) return {INF, INF};
  if(a<=l && r<=b) return tr[v];
  if(lazy[v]) spl(v);
  int mid=(l+r)/2;
  return min(cnt(2*v, l, mid, a, b), cnt(2*v+1, mid+1, r, a, b));
}
int dyst(int a, int b) {
  if(a<b) return b-a;
  return n-a+b;
}
pair<int,int>licz(int x) {
  auto it=A.lower_bound(x);
  int a=-1, b=-1;
  if(it==A.end()) {
    auto it2=A.begin();
    b=*it2;
  } else b=*it;
  if(it==A.begin()) {
    auto it2=A.end(); --it2;
    a=*it2;
  } else {
    --it;
    a=*it;
  }
  return {a, b};
}
void dodaj(int x) {
  if(A.size()==0) {
    A.insert(x);
    B.insert(x);
    return;
  }
  pair<int,int>p=licz(x);
  int a=p.st, b=p.nd;
  if(dyst(x, b)<k && B.find(b)!=B.end()) B.erase(b);
  if(dyst(a, x)>=k) B.insert(x);
  A.insert(x);
}
void usun(int x) {
  A.erase(x);
  if(B.find(x)!=B.end()) B.erase(x);
  if(A.size()==1) B.insert(*A.begin());
  if(A.size()<2) return;
  pair<int,int>p=licz(x);
  int a=p.st, b=p.nd;
  if(dyst(a, b)>=k) B.insert(b);
}
void init(int _k, vector<int>r) {
  n=r.size(); k=_k;
  while(N<n) N*=2;
  rep(i, n) tr[N+i]={r[i], i};
  for(int i=n; i<N; ++i) tr[N+i]={INF, INF};
  for(int i=N-1; i; --i) tr[i]=min(tr[2*i], tr[2*i+1]);
  rep(i, n) {
    while(tr[1].st==0) {
      dodaj(tr[1].nd);
      upd(1, 0, N-1, tr[1].nd, tr[1].nd, INF);
    }
    int x=*B.begin();
    usun(x);
    upd(1, 0, N-1, x-k+1, x, -1);
    if(x-k+1<0) upd(1, 0, N-1, n+x-k+1, n-1, -1);
    T[x]=n-i;
  }
}
int compare_plants(int x, int y) {
  if(T[x]>T[y]) return 1;
  return -1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Incorrect 0 ms 2396 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2444 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 2 ms 2396 KB Output is correct
7 Correct 40 ms 7284 KB Output is correct
8 Correct 2 ms 2504 KB Output is correct
9 Correct 2 ms 2396 KB Output is correct
10 Correct 38 ms 7252 KB Output is correct
11 Correct 34 ms 7268 KB Output is correct
12 Correct 36 ms 7360 KB Output is correct
13 Correct 52 ms 7284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2444 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 2 ms 2396 KB Output is correct
7 Correct 40 ms 7284 KB Output is correct
8 Correct 2 ms 2504 KB Output is correct
9 Correct 2 ms 2396 KB Output is correct
10 Correct 38 ms 7252 KB Output is correct
11 Correct 34 ms 7268 KB Output is correct
12 Correct 36 ms 7360 KB Output is correct
13 Correct 52 ms 7284 KB Output is correct
14 Correct 50 ms 8016 KB Output is correct
15 Correct 233 ms 14676 KB Output is correct
16 Correct 61 ms 9796 KB Output is correct
17 Correct 232 ms 14420 KB Output is correct
18 Correct 205 ms 18656 KB Output is correct
19 Correct 141 ms 15052 KB Output is correct
20 Correct 238 ms 14772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 36 ms 6896 KB Output is correct
4 Correct 152 ms 17140 KB Output is correct
5 Correct 213 ms 14840 KB Output is correct
6 Correct 198 ms 14452 KB Output is correct
7 Correct 223 ms 14672 KB Output is correct
8 Correct 226 ms 14288 KB Output is correct
9 Correct 170 ms 15884 KB Output is correct
10 Correct 183 ms 14692 KB Output is correct
11 Correct 160 ms 23028 KB Output is correct
12 Correct 109 ms 13904 KB Output is correct
13 Correct 193 ms 20820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Incorrect 0 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Incorrect 1 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Incorrect 0 ms 2396 KB Output isn't correct
5 Halted 0 ms 0 KB -