답안 #1079035

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1079035 2024-08-28T09:47:04 Z LIF Stranded Far From Home (BOI22_island) C++14
0 / 100
143 ms 24732 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[500005];
struct nod
{
    int val;
    int id;
}node[500005];
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 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Incorrect 2 ms 4576 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 Runtime error 143 ms 24728 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Runtime error 139 ms 24728 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Runtime error 139 ms 24732 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Incorrect 2 ms 4576 KB Output isn't correct
5 Halted 0 ms 0 KB -