結果

問題 No.3238 Shadow
コンテスト
ユーザー C
提出日時 2026-11-23 04:24:34
言語 C++23(gcc16)
(gcc 16.2.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc16.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 48 ms / 2,000 ms
+ 976µs
コード長 2,004 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 8,010 ms
コンパイル使用メモリ 420,236 KB
実行使用メモリ 9,900 KB
最終ジャッジ日時 2026-11-23 04:24:46
合計ジャッジ時間 10,630 ms
ジャッジサーバーID
(参考情報)
judge6_0 / judge5_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC optimize("O3")
#if defined(__x86_64__) || defined(__i386__)
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#endif
#endif
#include <bits/stdc++.h>
#include <atcoder/all>
#define each(x, v) for (auto&& x : v)
#define each2(x, y, v) for (auto&& [x, y] : v)
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(x) begin(x),end(x)
#define sz(x) (int)(x).size()
using namespace std;
using namespace atcoder;
using ll=long long;
using ull=unsigned long long;
using ld=long double;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vi>;
using pll=pair<ll,ll>;
using pi=pair<int,int>;

// using mint=modint998244353;
// using mint=modint1000000007;
// using mint2=static_modint<2>;

// using mint=LazyMontgomeryModInt<998244353>;
// using vm=vector<mint>;
// using vvm=vector<vm>;

int op(int a, int b) {
    return max(a, b);
}

int e() {
    return INT_MIN;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    /**
     * O(NlogN)
	 * 
	 * i < j かつ P_i < P_j の時有向辺(i,j)を追加すれば
	 * このDAGのトポロジカル順がわかれば元の問題が解けます
	 * (辺数がO(N^2)になるので、高速で求める必要があります)
	 * 
	 * P_1,P_2,... の順で処理します
	 * P_jを挿入する時、prefmx = max_{P_i < P_j : i < j} rank[i] とすれば
	 * rank[j] = prefmx + 1
	 * ということがわかります
	 * 
	 * segtree を使えば良いです
     */
    int N;
    cin>>N;
	segtree<int, op, e> seg(N+1);
	vector<pi>order(N,{INT_MAX,INT_MAX});
	rep(j,1,N+1){
		int p;
		cin>>p;
		int prefmx=seg.prod(0,p);
		if(prefmx==INT_MIN){
			auto&[x,y]=order[0];
			x=min(x,j);
			y=min(y,p);
			seg.set(p,0);
		}
		else{
			++prefmx;
			auto&[x,y]=order[prefmx];
			x=min(x,j);
			y=min(y,p);
			seg.set(p,prefmx);
		}
	}
	each2(x,y,order){
		if(x==INT_MAX)return 0;
		cout<<x<<' '<<y<<'\n';
	}
}
0