QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#499902#8783. Cherry PickingnahnWA 0ms18468kbC++143.2kb2024-07-31 20:06:362024-07-31 20:06:37

Judging History

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

  • [2024-07-31 20:06:37]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:18468kb
  • [2024-07-31 20:06:36]
  • 提交

answer

#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <deque>
#include <stack>
#include <queue>
#include <algorithm>
#include <cassert>
#include <random>
#include <chrono>
#include <iomanip>
#include <cmath>
#include <bitset>
#define int long long
#define double long double
#define ii pair<int,int>
#define iii pair<int, ii >
#define fi first
#define se second
#define getbit(x,y) (((x)>>(y))&1)
#define turnon(x,y) ((x)|(1ll<<y))
#define turnof(x,y) ((x)^(1ll<<y))
#define oo 1e18
#define pb push_back
#define all(x) x.begin(),x.end()
#define con(mask) mask=(mask-1)&mask
#define Unique(val) val.erase(unique(val.begin(),val.end()),val.end())

#define rand_int mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rand_ll mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int mod = 1e9 + 7;
const int base = 448;
using namespace std;

int n, k;
struct nhan {
    int r, ok, vt;

    nhan (int _r = 0, int _ok = 0, int _vt = 0): r(_r), ok(_ok), vt(_vt) {}

    bool operator < (const nhan &x) const {
        return r < x.r;
    }
} a[100005];

struct Node {
    int cnt, maxx, l, r;

    Node (int _cnt = 0, int _maxx = 0, int _l = 0, int _r = 0): cnt(_cnt), maxx(_maxx), l(_l), r(_r) {}
} st[400005];

Node merge(Node a, Node b, int l, int r) {
    int mid = (l + r) / 2;
    Node c(0, 0, 0, 0);
    c.cnt = a.cnt + b.cnt;
    c.maxx = max(a.maxx, b.maxx);
    c.maxx = max(c.maxx, a.r + b.l);
    c.l = a.l;
    c.r = b.r;

    if(a.cnt == mid - l + 1) c.l = a.maxx + b.l;
    if(b.cnt == r - mid) c.r = b.maxx + a.r;

    return c;
}

void build(int id, int l, int r) {
    if(l == r) {
        if(a[l].ok == 1) st[id] = Node(1, 1, 1, 1);
        else st[id] = Node(0, 0, 0, 0);
        return;
    }
    int mid = (l + r) / 2;
    build(2 * id, l, mid);
    build(2 * id + 1, mid + 1, r);

    st[id] = merge(st[2 * id], st[2 * id + 1], l, r);
}

void update(int id, int l, int r, int pos) {
    if(l > pos || r < pos) return;
    if(l == r && l == pos) {
        st[id] = Node(1, 0, 0, 0);
        return;
    }
    int mid = (l + r) / 2;
    update(2 * id, l, mid, pos);
    update(2 * id + 1, mid + 1, r, pos);
    st[id] = merge(st[2 * id], st[2 * id + 1], l, r);
}

signed main() {

    #ifndef ONLINE_JUDGE
    freopen("inp.inp","r",stdin);
    freopen("out.out","w",stdout);
    #endif //ONLINE_JUDGE

    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    cin >> n >> k;

    for(int i = 1; i <= n; i++) {
        cin >> a[i].r;
        a[i].vt = i;
    }

    for(int i = 1; i <= n; i++) {
        char x;
        cin >> x;
        a[i].ok = x - '0';
    }

    build(1, 1, n);
    sort(a + 1, a + n + 1);

    int res = 0;
    int pos = 0;

    for(int x = 1; x <= 100000; x++) {
        while(pos + 1 < n && a[pos + 1].r < x) {
            pos++;
            update(1, 1, n, a[pos].vt);
        }
        if(st[1].maxx >= k) res = x;
    }

    cout << res;







}
//      ProTeam
//(¯`·.·´¯) (¯`·.·´¯)
//`·.¸(¯`·.·´¯)¸ .·
//×°× ` ·.¸.·´ ×°×


Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5 2
1 2 3 4 5
01101

output:

2

result:

ok answer is '2'

Test #2:

score: 0
Accepted
time: 0ms
memory: 18468kb

input:

5 2
3 4 5 2 1
10101

output:

0

result:

ok answer is '0'

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 18392kb

input:

1 1
1
1

output:

100000

result:

wrong answer expected '1', found '100000'