結果
| 問題 |
No.1558 Derby Live
|
| コンテスト | |
| ユーザー |
Haa
|
| 提出日時 | 2021-06-25 22:00:28 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 309 ms / 2,000 ms |
| コード長 | 2,226 bytes |
| コンパイル時間 | 2,016 ms |
| コンパイル使用メモリ | 177,940 KB |
| 実行使用メモリ | 9,216 KB |
| 最終ジャッジ日時 | 2024-06-25 08:26:52 |
| 合計ジャッジ時間 | 12,136 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 33 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
template<typename T> bool chmax(T &x, const T &y) {return (x<y)?(x=y,true):false;};
template<typename T> bool chmin(T &x, const T &y) {return (x>y)?(x=y,true):false;};
constexpr ll MOD=998244353;
constexpr ll INF=2e18;
template<typename X>
struct Segtree{
using F=function<X(X,X)>;
int n; F f; X ex;
vector<X> dat;
Segtree(int n_, F f, X ex)
:f(f), ex(ex){
n=1;
while(n_>n){n*=2;}
dat.assign(2*n,ex);
}
void set(int i, X x){
dat[i+n-1]=x;
}
void build(){
for(int k=n-2;k>=0;k--)
dat[k]=f(dat[2*k+1],dat[2*k+2]);
}
void update(int i, X x){
i+=n-1;
dat[i]=x;
while(i>0){
i=(i-1)/2;
dat[i]=f(dat[i*2+1],dat[i*2+2]);
}
}
X query(int a, int b){
return query_sub(a,b,0,0,n);
}
X query_sub(int a, int b, int k, int l, int r){
if(r<=a||b<=l)
return ex;
else if(a<=l&&r<=b)
return dat[k];
else{
X vl=query_sub(a,b,k*2+1,l,(l+r)/2);
X vr=query_sub(a,b,k*2+2,(l+r)/2,r);
return f(vl,vr);
}
}
};
VI f(VI a, VI b){
int n=a.size();
VI ret(n);
REP(i,n){
ret[i]=b[a[i]];
}
return ret;
}
int main(){
int n, m, q; cin >> n >> m >> q;
VI e(n); iota(ALL(e),0);
Segtree<VI> seg(m+1,f,e);
int t, d, x, s, l, r, sum;
VI p(n);
REP(i,q){
cin >> t;
if(t==1){
cin >> d;
REP(j,n) cin >> p[j], p[j]--;
seg.update(d,p);
}
else if(t==2){
cin >> s;
VI ans=seg.query(0,s+1);
VI ans2(n);
REP(j,n) ans2[ans[j]]=j;
REP(j,n) cout << ans2[j]+1 << " ";
cout << endl;
}
else{
cin >> l >> r;
VI ans=seg.query(l,r+1);
sum=0;
REP(j,n) sum+=abs(j-ans[j]);
cout << sum << endl;
}
}
return 0;
}
Haa