結果

問題 No.1024 Children in a Row
ユーザー chocoruskchocorusk
提出日時 2020-04-11 15:02:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 747 ms / 2,000 ms
コード長 1,908 bytes
コンパイル時間 1,628 ms
コンパイル使用メモリ 116,052 KB
実行使用メモリ 36,548 KB
最終ジャッジ日時 2023-10-19 06:09:56
合計ジャッジ時間 21,514 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,024 KB
testcase_01 AC 2 ms
4,972 KB
testcase_02 AC 2 ms
5,028 KB
testcase_03 AC 3 ms
4,972 KB
testcase_04 AC 3 ms
5,028 KB
testcase_05 AC 3 ms
5,028 KB
testcase_06 AC 3 ms
5,028 KB
testcase_07 AC 3 ms
5,028 KB
testcase_08 AC 3 ms
4,972 KB
testcase_09 AC 4 ms
4,972 KB
testcase_10 AC 722 ms
32,324 KB
testcase_11 AC 691 ms
31,004 KB
testcase_12 AC 694 ms
31,796 KB
testcase_13 AC 693 ms
32,324 KB
testcase_14 AC 697 ms
31,268 KB
testcase_15 AC 725 ms
32,324 KB
testcase_16 AC 670 ms
31,532 KB
testcase_17 AC 591 ms
32,588 KB
testcase_18 AC 573 ms
32,324 KB
testcase_19 AC 744 ms
36,548 KB
testcase_20 AC 740 ms
36,548 KB
testcase_21 AC 743 ms
36,548 KB
testcase_22 AC 747 ms
36,548 KB
testcase_23 AC 716 ms
36,548 KB
testcase_24 AC 712 ms
36,548 KB
testcase_25 AC 723 ms
36,548 KB
testcase_26 AC 599 ms
36,548 KB
testcase_27 AC 597 ms
36,548 KB
testcase_28 AC 617 ms
36,548 KB
testcase_29 AC 497 ms
36,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n, m;
	cin>>n>>m;
	list<int> lst;
	vector<list<int>::iterator> v(n+m);
	for(int i=0; i<n; i++){
		v[i]=lst.insert(lst.end(), i);
	}
	int a[200020], b[200020], k[200020];
	int c[200020], d[400040], pr[200020];
	bool last[400040]={};
	iota(c, c+n, 0);
	iota(d, d+n, 0);
	fill(last, last+n, 1);
	for(int i=0; i<m; i++){
		cin>>a[i]>>b[i]>>k[i];
		a[i]--; b[i]--;
		v[n+i]=lst.insert(next(v[c[b[i]]]), n+i);
		lst.insert(next(v[n+i]), -i-1);
		last[c[a[i]]]=0;
		pr[i]=c[a[i]];
		c[a[i]]=n+i;
		d[n+i]=a[i];
		last[c[a[i]]]=1;
	}
	int idx=0;
	int l[400040], r[400040], rev[400040];
	int s[400040]; s[0]=0;
	for(auto x:lst){
		if(x<0) r[-x-1]=idx;
		else{
			l[x]=idx++;
			rev[l[x]]=x;
			s[idx]=s[idx-1]+last[x];
		}
	}
	for(int i=0; i<m; i++){
		int l1=l[n+i], r1=r[i], l2=l[pr[i]], ans;
		if(l2<l1){
			if(k[i]<=s[l2] || k[i]>s[r1]) ans=d[rev[lower_bound(s, s+n+m+1, k[i])-s-1]];
			else if(k[i]<=s[l2]+s[r1]-s[l1]) ans=d[rev[lower_bound(s, s+n+m+1, k[i]+s[l1]-s[l2])-s-1]];
			else ans=d[rev[lower_bound(s, s+n+m+1, k[i]-s[r1]+s[l1])-s-1]];
		}else{
			if(k[i]<=s[l1] || k[i]>s[l2]) ans=d[rev[lower_bound(s, s+n+m+1, k[i])-s-1]];
			else if(k[i]<=s[l1]+s[l2]-s[r1]) ans=d[rev[lower_bound(s, s+n+m+1, k[i]+s[r1]-s[l1])-s-1]];
			else ans=d[rev[lower_bound(s, s+n+m+1, k[i]-s[l2]+s[r1])-s-1]];
		}
		cout<<ans+1<<endl;
	}
	return 0;
}
0