Submission #738166

# Submission time Handle Problem Language Result Execution time Memory
738166 2023-05-08T08:33:23 Z bobthebuilder Comparing Plants (IOI20_plants) C++17
0 / 100
54 ms 4960 KB
#include "plants.h"
#include<bits/stdc++.h>
using namespace std;
#define sz(x) (int)x.size()
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define pb push_back
#define lowb(x) (x&(-x))
#define ALL(_x) _x.begin(),_x.end()
#define pii pair<int,int>
#define f first
#define s second
#define SORT_UNIQUE(x) sort(ALL(x)),x.erase(unique(ALL(x)),x.end())
#define ll long long
#define MNTO(x,y) x=min(x,y)
#define MXTO(x,y) x=max(x,y)
const int maxn=2e5+5;
const int INF=0x3f3f3f3f;
int seg[4*maxn],pos[4*maxn];
int arr[maxn];
int lazy[4*maxn];
void pushdown(int idx,int l,int r){
	if(!lazy[idx]){
		return;
	}
	seg[idx]+=lazy[idx];
	if(l==r){
		lazy[idx]=0;
		return;
	}
	lazy[idx*2]+=lazy[idx];
	lazy[idx*2+1]+=lazy[idx];
	lazy[idx]=0;
}
void build(int idx,int l,int r){
	
	if(l==r){
		seg[idx]=arr[l];
		pos[idx]=l;
		return;
	}
	int mid=(l+r)/2;
	build(idx*2,l,mid),build(idx*2+1,mid+1,r);
	seg[idx]=min(seg[idx*2],seg[idx*2+1]);
	if(seg[idx]==seg[idx*2]) pos[idx]=pos[idx*2];
	else pos[idx]=pos[idx*2+1];
}
void upd(int idx,int l,int r,int ql,int qr,int x){
	pushdown(idx,l,r);
	if(r<ql or l>qr) return;
	if(ql<=l and r<=qr){
		lazy[idx]+=x;
		pushdown(idx,l,r);
		return;
	}
	int mid=(l+r)/2;
	upd(idx*2,l,mid,ql,qr,x);
	upd(idx*2+1,mid+1,r,ql,qr,x);
	seg[idx]=min(seg[idx*2],seg[idx*2+1]);
	if(seg[idx]==seg[idx*2]) pos[idx]=pos[idx*2];
	else pos[idx]=pos[idx*2+1];
}
int ans[maxn];
void init(int k, std::vector<int> r) {
	--k;
	int n=sz(r);
	REP(i,n){
		arr[i]=r[i];
	}
	build(1,0,n-1);
	REP(i,n){
		int z=pos[1];
		ans[z]=n-i;
		if(z-k<0){
			upd(1,0,n-1,0,z-1,-1);
			upd(1,0,n-1,n+(z-k),n-1,-1);
		}
		else{
			upd(1,0,n-1,z-k,z-1,-1);
		}
		upd(1,0,n-1,z,z,INF);
	}
}

int compare_plants(int x, int y) {
	if(ans[x]>ans[y]){
		return 1;
	}
	return -1;
} 
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 0 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 1 ms 320 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 1 ms 320 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 420 KB Output is correct
3 Incorrect 54 ms 4960 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Incorrect 0 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 0 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -