結果

問題 No.1024 Children in a Row
ユーザー leaf_1415leaf_1415
提出日時 2020-04-14 17:29:07
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,245 bytes
コンパイル時間 2,295 ms
コンパイル使用メモリ 83,092 KB
実行使用メモリ 60,092 KB
最終ジャッジ日時 2024-04-09 13:15:45
合計ジャッジ時間 14,348 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
25,828 KB
testcase_01 AC 7 ms
25,948 KB
testcase_02 AC 7 ms
25,956 KB
testcase_03 WA -
testcase_04 AC 7 ms
25,972 KB
testcase_05 AC 8 ms
25,972 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 8 ms
25,860 KB
testcase_09 WA -
testcase_10 AC 390 ms
44,772 KB
testcase_11 AC 394 ms
42,180 KB
testcase_12 WA -
testcase_13 AC 407 ms
43,700 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 390 ms
43,968 KB
testcase_17 WA -
testcase_18 AC 342 ms
43,932 KB
testcase_19 WA -
testcase_20 AC 443 ms
49,340 KB
testcase_21 WA -
testcase_22 AC 439 ms
49,344 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 408 ms
50,688 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint n, m;
llint a[200005], b[200005], k[200005];
llint last[200005], qid[400005], val[400005];
vector<llint> G[400005];
llint l[200005], r[200005], pos[200005];
vector<llint> vec;

void dfs(int v)
{
	if(v > n) l[v-n] = (int)vec.size();
	
	if(last[val[v]] == v) vec.push_back(val[v]);
	else pos[qid[v]] = (int)vec.size();
	
	for(int i = (int)G[v].size()-1; i >= 0; i--) dfs(G[v][i]);
	
	if(v > n) r[v-n] = (int)vec.size()-1;
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m;
	for(int i = 1; i <= m; i++) cin >> a[i] >> b[i] >> k[i];
	
	for(int i = 1; i <= n; i++){
		last[i] = i, val[i] = i;
		if(i > 1) G[i-1].push_back(i);
	}
	
	for(int i = 1; i <= m; i++){
		G[last[b[i]]].push_back(n+i);
		val[n+i] = a[i];
		qid[last[a[i]]] = i;
		last[a[i]] = n+i;
	}
	
	dfs(1);
	
	//for(int i = 0; i < vec.size(); i++) cout << vec[i] << " "; cout << endl;
	//for(int i = 1; i <= m; i++) cout << l[i] << " " << r[i] << " " << pos[i] << endl;
	
	for(int i = 1; i <= m; i++){
		llint q = k[i]-1;
		if(l[i] < pos[i]){
			if(q < l[i]){
				cout << vec[q] << endl;
				continue;
			}
			q -= l[i];
			if(q < pos[i]-r[i]-1){
				cout << vec[r[i]+1 + q] << endl;
				continue;
			}
			q -= pos[i]-r[i]-1;
			if(q < r[i]-l[i]+1){
				cout << vec[l[i]+q] << endl;
				continue;
			}
			cout << vec[k[i]-1] << endl;
		}
		else{
			if(q < pos[i]){
				cout << vec[q] << endl;
				continue;
			}
			q -= pos[i];
			if(q < r[i]-l[i]+1){
				cout << vec[l[i]+q] << endl;
				continue;
			}
			q -= r[i]-l[i]+1;
			if(q < l[i]-pos[i]-1){
				cout << vec[pos[i] + q] << endl;
				continue;
			}
			cout << vec[k[i]-1] << endl;
		}
	}
	
	return 0;
}
0