답안 #1079042

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1079042 2024-08-28T09:48:52 Z LIF Stranded Far From Home (BOI22_island) C++14
15 / 100
165 ms 18340 KB
#include<bits/stdc++.h>
using namespace std;
int n,m;
int head[500005];
int cnt = 0;
long long int a[500005];
long long int su[500005];
bool last[800005];
struct nod
{
    int val;
    int id;
}node[800005];
void pushup(int rt)
{
    if(node[rt<<1].val > node[rt<<1|1].val)
    {
        node[rt].val = node[rt<<1].val;
        node[rt].id = node[rt<<1].id;
    }
    else
    {
        node[rt].val = node[rt<<1|1].val;
        node[rt].id = node[rt<<1|1].id;
    }
    return;
}
void build(int l,int r,int rt)
{
    if(l == r)
    {
        node[rt].val = a[l];
        node[rt].id = l;
        return;
    }
    int mid = (l+r)>>1;
    build(l,mid,rt<<1);
    build(mid+1,r,rt<<1|1);
    pushup(rt);
    return;
}
pair<int,int> query(int l,int r,int queryl,int queryr,int rt)
{
    if(queryl <= l && r <= queryr)
    {
        return make_pair(node[rt].val,node[rt].id);
    }
    pair<int,int> pp = make_pair(-1,0);
    int mid = (l+r)>>1;
    if(mid >= queryl)
    {
        pair<int,int> temp = query(l,mid,queryl,queryr,rt<<1);
        if(temp.first > pp.first)pp = temp;
    }
    if(mid+1 <= queryr)
    {
        pair<int,int> temp = query(mid+1,r,queryl,queryr,rt<<1|1);
        if(temp.first > pp.first)pp = temp;
    }
    return pp;
}
void solve(int l,int r,int rt) // rt 被包含在[l,r] // solve [l,rt-1] 和 [rt+1,r]
{
    //cout<<l<<" "<<r<<" "<<rt<<endl;
    if(l > r)return;
    if(l == r)
    {
        last[rt] = 1;
        return;
    }
    last[rt] = 1;
    //[l,rt-1];
    long long int all = su[rt-1] - su[l-1];
    if(all < a[rt])
    {
        for(int i=l;i<=rt-1;i++)last[i] = 0;
    }
    else
    {
        if(rt-1 >= l)
        {
            int nxt = query(1,n,l,rt-1,1).second;
            solve(l,rt-1,nxt);
        }
    }
    //[rt+1,r]
    all = su[r] - su[rt];
    if(all < a[rt])
    {
        for(int i=rt+1;i<=r;i++)last[i] = 0;
    }
    else
    {
        if(rt+1 <= r)
        {
            int nxt = query(1,n,rt+1,r,1).second;
            solve(rt+1,r,nxt);
        }
    }
}
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=m;i++)
    {
        int x,y;
        cin>>x>>y;
    }
    build(1,n,1);
    for(int i=1;i<=n;i++)su[i] = su[i-1] + a[i];
    int id = query(1,n,1,n,1).second;
    solve(1,n,id);
    for(int i=1;i<=n;i++)cout<<last[i];
    cout<<endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Incorrect 2 ms 4444 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Incorrect 147 ms 10656 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 146 ms 10400 KB Output is correct
3 Correct 133 ms 10576 KB Output is correct
4 Correct 149 ms 10412 KB Output is correct
5 Correct 92 ms 10420 KB Output is correct
6 Correct 145 ms 10404 KB Output is correct
7 Correct 165 ms 18340 KB Output is correct
8 Correct 164 ms 18260 KB Output is correct
9 Correct 125 ms 10412 KB Output is correct
10 Correct 136 ms 10576 KB Output is correct
11 Correct 95 ms 10580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Incorrect 143 ms 10424 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Incorrect 2 ms 4444 KB Output isn't correct
5 Halted 0 ms 0 KB -