TLE 20pts 求条
查看原帖
TLE 20pts 求条
322792
Alea楼主2024/11/13 23:05

代码如下:

// 洛谷 p3203 - 弹飞绵羊
#include <bits/stdc++.h>
using namespace std;
#define alea(pos) [(pos)/oe][(pos)%oe]
const int N=2e5+5,sN=449;
int n,oe,q,k[sN][sN];
int step[sN][sN],to_b[sN][sN],to_p[sN][sN];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    cin>>n;
    while(oe*oe<n) ++oe;
    for(int i=0;i<n;++i) cin>>k[i/oe][i%oe];
    for(int i=0;i<oe;++i){
        for(int j=oe-1;j>=0;--j){
            int nx=k[i][j]+i*oe+j;
            if(nx/oe==i){
                to_b[i][j]=to_b alea(nx);
                to_p[i][j]=to_p alea(nx);
                step[i][j]=step alea(nx)+1;
            }else{
                to_b[i][j]=nx/oe;
                to_p[i][j]=nx%oe;
                step[i][j]=1;
            }
        }
    }
    cin>>q;
    while(q--){
        int op,x,y;
        cin>>op>>x;
        if(op==1){
            int ew=x,ans=0;
            while(ew<n){
                ans+=step alea(ew);
                ew=(to_b alea(ew))*oe+(to_p alea(ew));
            }
            cout<<ans<<endl;
        }else{
            cin>>y;
            k alea(x)=y;
            for(int j=x%oe;j>=0;--j){
                int nx=k[x/oe][j]+(x/oe*oe)+j;
                if(nx/oe==x/oe){
                    to_b[x/oe][j]=to_b alea(nx);
                    to_p[x/oe][j]=to_p alea(nx);
                    step[x/oe][j]=step alea(nx)+1;
                }else{
                    to_b[x/oe][j]=nx/oe;
                    to_p[x/oe][j]=nx%oe;
                    step[x/oe][j]=1;
                }
            }
        }
    }
    return 0;
}

过了 #1,#3。感谢!

2024/11/13 23:05
加载中...