Submission #1079043

# Submission time Handle Problem Language Result Execution time Memory
1079043 2024-08-28T09:49:06 Z LIF Stranded Far From Home (BOI22_island) C++14
15 / 100
168 ms 18256 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;
}
# Verdict Execution time Memory 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 -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4552 KB Output is correct
3 Incorrect 138 ms 10584 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4696 KB Output is correct
2 Correct 136 ms 10580 KB Output is correct
3 Correct 141 ms 10412 KB Output is correct
4 Correct 142 ms 10420 KB Output is correct
5 Correct 91 ms 10580 KB Output is correct
6 Correct 148 ms 10576 KB Output is correct
7 Correct 168 ms 18256 KB Output is correct
8 Correct 168 ms 18256 KB Output is correct
9 Correct 119 ms 10408 KB Output is correct
10 Correct 117 ms 10580 KB Output is correct
11 Correct 92 ms 10576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Incorrect 134 ms 10416 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 -