結果

問題 No.1097 Remainder Operation
ユーザー 👑 potato167potato167
提出日時 2022-01-29 14:36:22
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 369 ms / 2,000 ms
コード長 1,636 bytes
コンパイル時間 2,421 ms
コンパイル使用メモリ 215,672 KB
実行使用メモリ 59,812 KB
最終ジャッジ日時 2023-08-30 12:38:05
合計ジャッジ時間 10,286 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 29 ms
8,524 KB
testcase_08 AC 29 ms
8,676 KB
testcase_09 AC 29 ms
8,612 KB
testcase_10 AC 29 ms
8,568 KB
testcase_11 AC 29 ms
8,664 KB
testcase_12 AC 329 ms
59,672 KB
testcase_13 AC 349 ms
59,524 KB
testcase_14 AC 357 ms
59,476 KB
testcase_15 AC 361 ms
59,512 KB
testcase_16 AC 343 ms
59,564 KB
testcase_17 AC 280 ms
59,560 KB
testcase_18 AC 256 ms
59,480 KB
testcase_19 AC 283 ms
59,524 KB
testcase_20 AC 281 ms
59,620 KB
testcase_21 AC 365 ms
59,812 KB
testcase_22 AC 369 ms
59,668 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
using std::cout;
using std::cin;
using std::endl;

namespace po167{
template<class T,T(*op)(T,T)>
struct Doubling_op
{
	int _n;
	long long Log;
	std::vector<std::vector<int>> index_data;
	std::vector<std::vector<T>> value_data;
	Doubling_op(int n,long long limit,std::vector<int> index,std::vector<T> value):_n(n){
		Log=2;
		while(limit){
			limit/=2;
			Log++;
		}
		index_data.resize(Log);
		value_data.resize(Log);
		index_data[0]=index;
		value_data[0]=value;
		for(int i=1;i<Log;i++){
			index_data[i].resize(_n);
			value_data[i].resize(_n);
			for(int j=0;j<_n;j++){
				int tmp=index_data[i-1][j];
				index_data[i][j]=index_data[i-1][tmp];
				value_data[i][j]=op(value_data[i-1][j],value_data[i-1][tmp]);
			}
		}
	}
	std::pair<int,T> query(long long times,int start_index,T start_value){
		for(int i=0;i<Log;i++){
			if(times&1){
				start_value=op(start_value,value_data[i][start_index]);
				start_index=index_data[i][start_index];
			}
			times>>=1;
		}
		return std::make_pair(start_index,start_value);
	}
};
}

using doubleing_F=long long;
doubleing_F d_op(doubleing_F l,doubleing_F r){
	return l+r;
}

void solve();

//  rainy ~ 雨に打たれて ~
int main() {
	
	int t=1;
	//cin>>t;
	solve();
}

void solve(){
	int n;
	cin>>n;
	std::vector<int> q(n);
	std::vector<long long> p(n);
	for(int i=0;i<n;i++) cin>>p[i];
	for(int i=0;i<n;i++){
		q[i]=(i+p[i])%n;
	}
	long long L=1e13;
	po167::Doubling_op<doubleing_F,d_op> D(n,L,q,p);
	int Q;
	cin>>Q;
	for(int i=0;i<Q;i++){
		long long k;
		cin>>k;
		cout<<D.query(k,0,0).second<<"\n";
	}
	
}
0