显示代码纯文本
#include<bits/stdc++.h>
#define intw long long
#define re register
#define il inline
#define inf 1e9
#define eps 1e-15
#define ll long long
#define mod 1000000
#define bianli for(int i=head[x];i;i=a[i].next)
#define QWQ cout<<"qwq"
#define me(qw) memset(qw,0,sizeof(qw));
#define meinf(qw) memset(qw,0x3f,sizeof(qw));
using namespace std;
const int maxn=100005;
vector<int>v[maxn];
struct ccc{int to,next;}a[maxn*2];
int viss[maxn];
int cmt,xia[maxn],tp[maxn],size[maxn],qwq,ans,ru[maxn],belong[maxn],tmp,vis[maxn],cnt,low[maxn],dfn[maxn],sta[maxn],top,head[maxn],tot=0;
void add(int x,int y){
a[++tot].to=y;
a[tot].next=head[x];
head[x]=tot;}
void tarjan(int x){
dfn[x]=low[x]=++cnt;
sta[++top]=x;
vis[x]=1;
for(int i=head[x];i;i=a[i].next){
int to=a[i].to;
if(dfn[to]==0){
tarjan(to);
low[x]=min(low[to],low[x]);}
else if(vis[to]==1)
low[x]=min(low[x],dfn[to]);}
if(low[x]==dfn[x]){qwq++;
do{
tmp=sta[top--];
++size[qwq];
tp[qwq]=tmp;
vis[tmp]=0;
belong[tmp]=qwq;}
while(tmp!=x);}}
int q,w,s[maxn];
void work(int l,int r){
for(int i=0;i<(r-l+1)/2;i++){
swap(s[l+i],s[r-i]);}}
void _dfs(int x,int step){
if(viss[x])return;
viss[x]=1;
v[step].push_back(x);
xia[x]=cmt;
++cmt;
bianli{
int to=a[i].to;
_dfs(to,step);
}}
int main(){
freopen("usaco_Feb_swap.in","r",stdin);
freopen("usaco_Feb_swap.out","w",stdout);
int n,m,k;
cin>>n>>m>>k;
for(int i=1;i<=n;i++)s[i]=i;
for(int i=1;i<=m;i++){
cin>>q>>w;
work(q,w);}
for(int i=1;i<=n;i++)add(i,s[i]);
//for(int i=1;i<=n;i++)cout<<s[i]<<' ';
for(int i=1;i<=n;i++)if(!dfn[i])tarjan(i);
//for(int i=1;i<=n;i++)cout<<size[belong[i]];
for(int i=1;i<=qwq;i++)
cmt=0,_dfs(tp[i],i);
for(int i=1;i<=n;i++){
int sz=v[belong[i]].size();
cout<<v[belong[i]][(k+xia[i])%sz]<<endl;
}
return 0;
}