QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#418649#3744. Fixed PointZayinCTT#AC ✓533ms16988kbC++113.0kb2024-05-23 14:58:392024-05-23 14:58:40

Judging History

This is the latest submission verdict.

  • [2024-05-23 14:58:40]
  • Judged
  • Verdict: AC
  • Time: 533ms
  • Memory: 16988kb
  • [2024-05-23 14:58:39]
  • Submitted

answer

// 那就是希望。
// 即便需要取模,也是光明。

#include <algorithm>
#include <stdio.h>
#include <vector>
typedef long long llt;
typedef unsigned uint;typedef unsigned long long ullt;
typedef bool bol;typedef char chr;typedef void voi;
typedef double dbl;
template<typename T>bol _max(T&a,T b){return(a<b)?a=b,true:false;}
template<typename T>bol _min(T&a,T b){return(b<a)?a=b,true:false;}
template<typename T>T lowbit(T n){return n&-n;}
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T>T lcm(T a,T b){return(a!=0||b!=0)?a/gcd(a,b)*b:(T)0;}
template<typename T>T exgcd(T a,T b,T&x,T&y){if(b!=0){T ans=exgcd(b,a%b,y,x);y-=a/b*x;return ans;}else return y=0,x=1,a;}
template<typename T>T power(T base,T index,T mod)
{
    T ans=1%mod;
    while(index)
    {
        if(index&1)ans=ans*base%mod;
        base=base*base%mod,index>>=1;
    }
    return ans;
}
// Your shadow Gets in the way of my light
uint A[11][100005],T[100005],Id[100005],n,m,q;
uint Mod[2005],tp;
bol B[100005];
std::vector<uint>Cnt[10][2005];

int main()
{
#ifdef MYEE
    freopen("QAQ.in","r",stdin);
    freopen("QAQ.out","w",stdout);
#endif
    while(scanf("%u%u%u",&n,&m,&q)==3&&n&&m&&q)
    {
        for(uint i=0;i<n;i++)A[0][i]=i;
        for(uint i=0;i<m;i++)
        {
            uint l,r;scanf("%u%u",&l,&r),l--;
            for(uint j=0;j<n;j++)A[i+1][j]=A[i][j];
            for(uint j=0;j<r-l;j++)A[i+1][r-j-1]=A[i][l+j];
        }
        for(uint i=0;i<n;i++)B[i]=0;
        std::vector<std::pair<uint,uint> >P;
        for(uint i=0;i<n;i++)if(!B[i])
        {
            uint c=0;do B[i]=1,c++,i=A[m][i];while(!B[i]);
            P.push_back({c,i});
        }
        std::sort(P.begin(),P.end()),tp=0;
        for(auto s:P)if(!tp||Mod[tp-1]!=s.first)Mod[tp++]=s.first;
        for(uint i=0;i<m;i++)
        {
            for(uint j=0;j<tp;j++)Cnt[i][j].clear();
            for(uint j=0;j<n;j++)T[A[i][j]]=j,Id[j]=-1;
            uint c=0;
            for(auto s:P)
            {
                if(s.first!=Mod[c])c++;
                std::vector<uint>V{s.second};
                while(V.size()<s.first)V.push_back(A[m][V.back()]);
                std::reverse(V.begin(),V.end());
                for(uint j=0;j<s.first;j++)Id[V[j]]=j;
                for(uint j=0;j<s.first;j++)if(~Id[T[V[j]]])
                    Cnt[i][c].push_back((j-Id[T[V[j]]]+s.first)%s.first);
                for(uint j=0;j<s.first;j++)Id[V[j]]=-1;
            }
            for(uint j=0;j<tp;j++)std::sort(Cnt[i][j].begin(),Cnt[i][j].end());
        }
        while(q--)
        {
            uint k;scanf("%u",&k);
            uint r=k%m,t=k/m;
            uint ans=0;
            for(uint i=0;i<tp;i++)
                ans+=std::upper_bound(Cnt[r][i].begin(),Cnt[r][i].end(),t%Mod[i])
                        -std::lower_bound(Cnt[r][i].begin(),Cnt[r][i].end(),t%Mod[i]);
            printf("%u\n",ans);
        }
    }
    return 0;
}

// 那就是希望。
// 即便需要取模,也是光明。

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 533ms
memory: 16988kb

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