Submission #794814

# Submission time Handle Problem Language Result Execution time Memory
794814 2023-07-26T23:39:16 Z vjudge1 Comparing Plants (IOI20_plants) C++17
0 / 100
1 ms 340 KB
#include "plants.h"
#include <bits/stdc++.h>
#define N 200100
int pos[N], cnt;
int mval[4*N], mpos[4*N], l[4*N],r[4*N], sub[4*N];
void pd(int n) {
    if(sub[n]) {
        mval[n]-=sub[n];
        if(l[n]!=r[n])
            sub[n*2]+=sub[n],
            sub[n*2+1]+=sub[n];
        sub[n] = 0;
    }
}
void upd(int n) {
    if(mval[2*n]<mval[2*n+1])
        mval[n] = mval[2*n+1],
        mpos[n] = mpos[2*n+1];
    else mval[n] = mval[2*n],
        mpos[n] = mpos[2*n];
}
std::vector<int> R;
void build(int i, int lp, int rp) {
    l[i] = lp, r[i] = rp;
    if(lp==rp)
        mval[i] = R[lp-1],
        mpos[i] = lp;
    else build(i*2,lp,lp+rp>>1),
        build(i*2+1,lp+rp+1>>1,rp),
        upd(i);
}
#define n R.size()
void update(int i, int rl, int rr, int v) {
    pd(i);
    if(rl<=l[i]&&r[i]<=rr)
        return (void)(sub[i]-=v,pd(i));
    if(rl<=r[i*2])
        update(i*2,rl,rr,v);
    if(r[i*2]<rr)
        update(i*2+1,rl,rr,v);
    upd(i);
}
void init(int k, std::vector<int> _r) {
    R = _r;
    build(1,1,n);
    for(int i = 0; i < n; i++) {
        int x = mpos[1];
        pos[x] = ++cnt;
        if(x<k) {
            update(1,1,x,-1);
            update(1,n-k+x+1,n,-1);
        } else {
            update(1,x-1+1,x,-1);
        }
        update(1,x,x,-1e9);
    }
	return;
}

int compare_plants(int x, int y) {
	return pos[x]<pos[y]?1:-1;
}

Compilation message

plants.cpp: In function 'void build(int, int, int)':
plants.cpp:28:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   28 |     else build(i*2,lp,lp+rp>>1),
      |                       ~~^~~
plants.cpp:29:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   29 |         build(i*2+1,lp+rp+1>>1,rp),
      |                     ~~~~~^~
plants.cpp: In function 'void init(int, std::vector<int>)':
plants.cpp:46:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for(int i = 0; i < n; i++) {
      |                      ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 0 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 0 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -