結果
問題 | No.1097 Remainder Operation |
ユーザー |
|
提出日時 | 2024-08-12 10:25:59 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 39 ms / 2,000 ms |
コード長 | 1,786 bytes |
コンパイル時間 | 1,830 ms |
コンパイル使用メモリ | 192,220 KB |
最終ジャッジ日時 | 2025-02-23 22:36:15 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 21 |
ソースコード
//Shirasu Azusa 2024.08#include <bits/stdc++.h>#define fi first#define se second#define eb emplace_back#define mp make_pairusing namespace std;typedef long double ld;typedef long long ll;typedef unsigned long long ull;template<typename T,typename U>T ceil(T x, U y) {return (x>0?(x+y-1)/y:x/y);}template<typename T,typename U>T floor(T x, U y) {return (x>0?x/y:(x-y+1)/y);}template<class T,class S>bool chmax(T &a,const S b) {return (a<b?a=b,1:0);}template<class T,class S>bool chmin(T &a,const S b) {return (a>b?a=b,1:0);}int popcnt(int x) {return __builtin_popcount(x);}int popcnt(ll x) {return __builtin_popcountll(x);}int topbit(int x) {return (x==0?-1:31-__builtin_clz(x));}int topbit(ll x) {return (x==0?-1:63-__builtin_clzll(x));}int lowbit(int x) {return (x==0?-1:__builtin_ctz(x));}int lowbit(ll x) {return (x==0?-1:__builtin_ctzll(x));}#define int long long#define rep(i,a,b) for(int i=(a);i<=(b);i++)#define per(i,a,b) for(int i=(a);i>=(b);i--)typedef pair<int,int> pii;typedef vector<int> vi;typedef vector<pii> vp;typedef tuple<int,int,int> tiii;int read() {int x=0,w=1; char c=getchar();while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();}return x*w;}const int N=2e5+5;int n,a[N],q,ans[N],vst[N],b[N],m,t,l,sum,s[N];signed main() {n=read();rep(i,0,n-1) a[i]=read();m=1; b[1]=0; vst[0]=1;for(int x=0;;) {x=(x+a[x])%n;if(vst[x]) {t=x; break;}else vst[x]=1, b[++m]=x;}rep(i,1,m) if(b[i]==t) {l=i; break;}rep(i,1,m) s[i]=s[i-1]+a[b[i]];rep(i,l,m) sum+=a[b[i]]; int pp=(m-l+1);q=read();rep(i,1,q) {int k=read();if(k<l) printf("%lld\n",s[k]);else printf("%lld\n",s[(k-l+1)%pp+l-1]+sum*((k-l+1)/pp));}return 0;}