이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define lp (pos+pos+1)
#define rp (2*pos+2)
#define m (l+r)/2
using namespace std;
int pt;
int rep[500009],sz[500009];
int find(int x)
{
if(x==-1)return -1;
while(x!=rep[x])x=rep[x];
}
void cn(int x,int y)
{
if(min(x,y)==-1)return;
x=find(x);y=find(y);
if(x==y)return;
if(sz[x]<sz[y])swap(x,y);
sz[x]+=sz[y];
rep[y]=x;
}
int seg[1200009],a[300009];
void laz(int pos,int l,int r)
{
if(seg[pos]==-1)return;
seg[pos]=find(seg[pos]);
if(l==r)
{
cn(seg[pos],a[l]);
a[l]=find(seg[pos]);
seg[pos]=-1;
return;
}
cn(seg[pos],seg[lp]);
cn(seg[pos],seg[rp]);
seg[pos]=find(seg[pos]);
seg[lp]=seg[pos];
seg[rp]=seg[pos];
seg[pos]=-1;
}
void upd(int pos,int l,int r,int b,int e,int o)
{
laz(pos,l,r);
if(b<=l&&r<=e)
{
seg[pos]=o;
laz(pos,l,r);
return;
}
if(m>=b)upd(lp,l,m,b,e,o);
if(m<e)upd(rp,m+1,r,b,e,o);
}
void frsh(int pos,int l,int r)
{
laz(pos,l,r);
if(l==r)return;
frsh(lp,l,m);
frsh(rp,m+1,r);
}
int n,q,x,y;
int vis[300009];
int main()
{
memset(a,-1,sizeof(a));
memset(seg,-1,sizeof(seg));
cin>>n>>q;
for(int i=0;i<q;i++)
{
sz[i]=1;
rep[i]=i;
}
for(int i=0;i<n-1;i++)cin>>x>>x;
for(int i=0;i<q;i++)
{
cin>>x>>y;
x--;y-=2;
upd(0,0,n-2,x,y,i);
}
frsh(0,0,n-2);
int ans=1;
for(int i=0;i<n-1;i++)
{
if(a[i]==-1)ans*=2;
else
{
a[i]=find(a[i]);
if(vis[a[i]])continue;
vis[a[i]]=1;
ans*=2;
}
}
cout<<ans;
}
컴파일 시 표준 에러 (stderr) 메시지
usmjeri.cpp: In function 'int find(int)':
usmjeri.cpp:12:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |