QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#397532#3744. Fixed PointGraphcityAC ✓120ms18912kbC++201.6kb2024-04-24 11:51:482024-04-24 11:51:48

Judging History

This is the latest submission verdict.

  • [2024-04-24 11:51:48]
  • Judged
  • Verdict: AC
  • Time: 120ms
  • Memory: 18912kb
  • [2024-04-24 11:51:48]
  • Submitted

answer

#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rof(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
const int Maxn=1e5;

int n,m,q,s,L[Maxn+5],R[Maxn+5],a[Maxn+5];
int p[Maxn+5],id[Maxn+5],pos[Maxn+5],len[Maxn+5];
int ans[Maxn+5],K[Maxn+5],f[705][Maxn+5];
int to[Maxn+5],dx[Maxn+5],cur;
vector<int> qr[Maxn+5];

inline void Clear()
{
    For(i,0,m-1) vector<int>().swap(qr[i]);
    For(i,0,n) id[i]=pos[i]=len[i]=to[i]=dx[i]=0;
    For(i,0,q) ans[i]=0; s=cur=0;
}
inline void Work(int x)
{
    For(i,1,n)
    {
        int k=a[i],p=id[i]; if(id[i]!=id[k]) continue;
        int w=(pos[k]-pos[i]+len[p])%len[p]; f[to[len[p]]][w]++;
    }
    for(auto id:qr[x]) {int k=K[id]/m; For(i,1,cur) ans[id]+=f[i][k%dx[i]];}
    For(i,1,n)
    {
        int k=a[i],p=id[i]; if(id[i]!=id[k]) continue;
        int w=(pos[k]-pos[i]+len[p])%len[p]; f[to[len[p]]][w]=0;
    }
}
inline void Solve()
{
    cin>>m>>q,s=0,iota(a+1,a+n+1,1);
    For(i,1,m) {cin>>L[i]>>R[i]; reverse(a+L[i],a+R[i]+1);}
    For(i,1,n) p[a[i]]=i,id[i]=0;
    For(i,1,n) if(!id[i])
    {
        ++s; for(int j=p[i];;j=p[j])
            {id[j]=s,pos[j]=len[s]++; if(j==i) break;}
        if(!to[len[s]]) to[len[s]]=++cur,dx[cur]=len[s];
    }
    For(i,1,q) cin>>K[i],qr[K[i]%m].push_back(i);
    iota(a+1,a+n+1,1);
    For(i,0,m-1) Work(i),reverse(a+L[i+1],a+R[i+1]+1);
    For(i,1,q) cout<<ans[i]<<endl; Clear();
}

int main()
{
    // freopen("1.in","r",stdin);

    ios::sync_with_stdio(false);
    while(cin>>n) Solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 120ms
memory: 18912kb

input:

100000 10 100000
3135 43886
11880 99989
6753 75994
49859 61511
34135 56769
36040 94909
31157 40208
1045 52859
17015 29390
34992 75590
427894487
754397106
304363104
288735752
794969909
361436976
343784951
800838635
507520362
111733743
43029867
107598330
993009440
179455786
17298032
187551627
96418485...

output:

1055
1055
1056
1057
1056
1785
1055
1056
1055
1057
1055
1055
1785
1055
1056
1055
1055
1056
1055
1785
1055
1056
1060
1055
1057
1056
1785
1056
1057
6417
3372
1057
1055
1057
1068
3371
1055
1055
1785
1055
1055
6417
1056
1056
1787
1055
1061
1056
1055
1056
1055
1056
1786
1056
1055
1811
1785
4101
1785
1055
...

result:

ok 500000 numbers