結果

問題 No.3396 ChRisTmas memory
コンテスト
ユーザー Mike scarf
提出日時 2025-12-12 15:23:04
言語 C++17
(gcc 13.3.0 + boost 1.89.0)
結果
TLE  
実行時間 -
コード長 1,707 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,613 ms
コンパイル使用メモリ 195,096 KB
実行使用メモリ 11,428 KB
最終ジャッジ日時 2025-12-12 15:23:39
合計ジャッジ時間 31,432 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30 TLE * 1 -- * 9
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:22:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   22 |     scanf("%lld",&t);
      |     ~~~~~^~~~~~~~~~~
main.cpp:25:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   25 |         scanf("%lld",&op);
      |         ~~~~~^~~~~~~~~~~~
main.cpp:27:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   27 |             scanf("%lld%lld",&m,&r);
      |             ~~~~~^~~~~~~~~~~~~~~~~~
main.cpp:51:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   51 |             scanf("%lld",&k);
      |             ~~~~~^~~~~~~~~~~
main.cpp:58:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   58 |             scanf("%lld",&m);
      |             ~~~~~^~~~~~~~~~~

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=15000;
ll s[maxn+5],p[maxn+5],q[maxn+5],s1[maxn+5];
ll cnt,lim;
ll gcd(ll a,ll b){
    return b?gcd(b,a%b):a;
}
ll egcd(ll a,ll b,ll &x,ll &y){
    ll d;
    if(b==0){
        x=1,y=0;
        return a;
    }
    d=egcd(b,a%b,y,x);
    y-=a/b*x;
    return d;
}
int main(){
    ll t,op,m,r,k,i,j,zc,zc1,zc2,cur,cur1,ans,x,y,d;
    scanf("%lld",&t);
    cnt=0,lim=0;
    while(t--){
        scanf("%lld",&op);
        if(op==1){
            scanf("%lld%lld",&m,&r);
            cnt++;
            s[cnt]=m,p[cnt]=r;
            if(cnt-1==lim){
                zc=m;
                for(i=1;i<cnt;i++){
                    zc/=gcd(zc,q[i]);
                }
                q[cnt]=zc;
                cur=1,zc1=0;
                for(i=1;i<cnt;i++){
                    zc1=(zc1+s1[i]*cur)%m;
                    cur=(cur*q[i])%m;
                }
                zc2=(r-zc1%m+m)%m;
                d=egcd(cur,m,x,y);
                if(zc2%d==0){
                    x=(x%m+m)%m;
                    s1[cnt]=(x*(zc2/d))%(m/d);
                    lim++;
                }
            }
        }
        else if(op==2){
            scanf("%lld",&k);
            cnt-=k;
            if(lim>cnt){
                lim=cnt;
            }
        }
        else{
            scanf("%lld",&m);
            if(lim<cnt){
                printf("-1\n");
            }
            else{
                ans=0,cur=1;
                for(i=1;i<=cnt;i++){
                    ans=(ans+s1[i]*cur)%m;
                    cur=(cur*q[i])%m;
                }
                printf("%lld\n",ans);
            }
        }
    }
    return 0;
}
0