#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 |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Incorrect |
142 ms |
10420 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
137 ms |
10416 KB |
Output is correct |
3 |
Correct |
153 ms |
15188 KB |
Output is correct |
4 |
Correct |
141 ms |
14928 KB |
Output is correct |
5 |
Correct |
93 ms |
13476 KB |
Output is correct |
6 |
Correct |
140 ms |
15140 KB |
Output is correct |
7 |
Correct |
173 ms |
22868 KB |
Output is correct |
8 |
Correct |
167 ms |
22816 KB |
Output is correct |
9 |
Correct |
122 ms |
14368 KB |
Output is correct |
10 |
Correct |
124 ms |
14160 KB |
Output is correct |
11 |
Correct |
98 ms |
13652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Incorrect |
137 ms |
10416 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 |
- |