답안 #828457

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
828457 2023-08-17T09:50:21 Z minhcool 식물 비교 (IOI20_plants) C++17
0 / 100
1 ms 312 KB
//#define local
#ifndef local
#include "plants.h"
#endif
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
//#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
 
const int N = 3e5 + 5;
 
const int oo = 1e9 + 7, mod = 1e9 + 7;
 
mt19937 rng(1);
 
int rnd(int l, int r){
	int temp = rng() % (r - l + 1);
	return abs(temp) + l;
}
 
int a[N];
 
int mini[N << 2], laz[N << 2];
 
void build(int id, int l, int r){
    if(l == r){
        mini[id] = a[id];
        return;
    }
    int mid = (l + r) >> 1;
    build(id << 1, l, mid);
    build(id << 1 | 1, mid + 1, r);
    mini[id] = min(mini[id << 1], mini[id << 1 | 1]);
}
 
void lazy(int id){
    int t = laz[id];
    if(!t) return;
    mini[id << 1] += t;
    mini[id << 1 | 1] += t;
    laz[id << 1] += t;
    laz[id << 1 | 1] += t;
    laz[id] = 0;
}
 
void upd(int id, int l, int r, int L, int R, int val){
    if(l > R || r < L) return;
    if(l >= L && r <= R){
        mini[id] += val;
        laz[id] += val;
        return;
    }
    lazy(id);
    int mid = (l + r) >> 1;
    upd(id << 1, l, mid, L, R, val);
    upd(id << 1 | 1, mid + 1, r, L, R, val);
    mini[id] = min(mini[id], mini[id << 1]);
}
 
void er(int id, int l, int r, int pos){
    if(l == r){
        mini[id] = oo;
        return;
    }
    lazy(id);
    int mid = (l + r) >> 1;
    if(pos <= mid) er(id << 1, l, mid, pos);
    else er(id << 1 | 1, mid + 1, r, pos);
}
 
int get(int id, int l, int r){
    if(mini[id] > 0) return oo;
    if(l == r) return l;
    lazy(id);
    int mid = (l + r) >> 1;
    if(mini[id << 1] == 0) return get(id << 1, l, mid);
    else return get(id << 1 | 1, mid + 1, r);
}
 
int b[N];
 
void init(int k, vector<int> r){
    k--;
    int n = r.size();
    for(int i = 0; i < n; i++) a[i] = r[i];
    build(1, 0, n - 1);
    for(int i = 0; i < n; i++){
        int temp = get(1, 0, n - 1);
        if(temp == oo) return;
        b[temp] = i;
        er(1, 0, n - 1, temp);
        upd(1, 0, n - 1, max(0, i - k), i - 1, -1);
        if(i < k) upd(1, 0, n - 1, n + i - k, n - 1, -1);
    }
}
 
int compare_plants(int x, int y){
    if(a[x] < a[y]) return -1;
    if(a[x] > a[y]) return 1;
    return 0;
}
 
 
#ifdef local
void process(){
 
}
 
signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	process();
}
#endif
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 276 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 312 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -