QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#798379#8783. Cherry Pickingpiaoyun#WA 1ms11832kbC++202.0kb2024-12-04 13:03:042024-12-04 13:03:04

Judging History

你现在查看的是最新测评结果

  • [2024-12-04 13:03:04]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:11832kb
  • [2024-12-04 13:03:04]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 1e6 + 10;
int N,M,K,Q;
int a[MAXN];
string str;
int fa[MAXN];
int sz[MAXN];
int L[MAXN];
int R[MAXN];
int getfa(int x){
    if(fa[x] == x) return x;
    return fa[x] = getfa(fa[x]);
}

int tot = 0;

void merge(int x, int y){
    x = getfa(x);
    y = getfa(y);
    if(x == y) return;
    if(sz[x] >= K) tot--;
    if(sz[y] >= K) tot--;
    fa[y] = x;
    sz[x] += sz[y];
    if(sz[x] >= K) tot++;
    L[x] = min(L[x], L[y]);
    R[x] = max(R[x], R[y]);
}

int getsz(int x){
    return sz[getfa(x)];
}

void prepare(){
	cin >> N >> K;
	for(int i = 1; i <= N; i++){
		cin >> a[i];
	}
    cin >> str;
    for(int i = 1; i <= N; i++){
        sz[i] = str[i-1] - '0';
        fa[i] = i;
        if(K == 1) tot += str[i-1] - '0';
        L[i] = R[i] = i;
    }
    for(int i = 1; i <= N - 1; i++){
        if(sz[i] && sz[i+1]){
            merge(i, i+1);
        }
    }
    vector<pair<int,int>> v;
    for(int i = 1; i <= N; i++){
        v.emplace_back(a[i], i);
    }
    sort(v.begin(), v.end());
    int ans = 0;
    for(int l = 0, r = 0; l < N; l = r){
        while(r < N && v[r].first == v[l].first){
            r++;
        }
        for(int i = l; i < r; i++){
            int p = v[i].second;
            int f = getfa(p);
            if(str[p - 1] == '1'){
                if(sz[f] >= K) tot--;
                sz[f]--;
                if(sz[f] >= K) tot++;
            }
            if(sz[f] == 0){
                if(L[f] > 1){
                    merge(L[f]-1, L[f]);
                }
                int g = getfa(f);
                if(sz[g] > 0 && sz[R[g]+1] > 0){
                    merge(R[g], R[g] + 1);
                }
            }
        }
        if(tot) ans = max(ans, v[l].first + 1);
    }
    cout << ans << '\n';
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int T = 1;
	// cin >> T;
	while(T--){
		prepare();
	}
}



詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 11780kb

input:

5 2
1 2 3 4 5
01101

output:

2

result:

ok answer is '2'

Test #2:

score: 0
Accepted
time: 1ms
memory: 11724kb

input:

5 2
3 4 5 2 1
10101

output:

0

result:

ok answer is '0'

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 11832kb

input:

1 1
1
1

output:

0

result:

wrong answer expected '1', found '0'