結果
| 問題 |
No.1558 Derby Live
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-06-26 08:57:19 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,925 bytes |
| コンパイル時間 | 3,962 ms |
| コンパイル使用メモリ | 204,992 KB |
| 最終ジャッジ日時 | 2025-01-22 13:02:24 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 2 |
| other | AC * 3 WA * 30 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
#include <cstdint>
#include <string>
#include <sstream>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
using P=pair<ll,ll>;
const int INF=INT_MAX;
const int mod=1e9+7;
struct SegmentTree {
private:
int n;
vector<vector<int>> node;
public:
vector<int>comp(vector<int>l,vector<int>r){
int sz=l.size();
vector<int>s(sz);
rep(i,sz){s[i]=r[l[i]];}
return s;
}
SegmentTree(int m,int sz) {
n = 1; while(n < m) n *= 2;
vector<int>res(sz);
iota(res.begin(),res.end(),0);
node.resize(2*n-1,res);
for(int i=0; i<n; i++) node[i+n-1] = res;
for(int i=n-2; i>=0; i--) node[i] = comp(node[2*i+1],node[2*i+2]);
}
void update(int x, vector<int> val) {
x += (n - 1);
node[x] = val;
while(x > 0) {
x = (x - 1) / 2;
int sz=val.size();
node[x] = comp(node[2*x+1],node[2*x+2]);
}
}
vector<int> get(int a, int b, int sz,int k=0, int l=0, int r=-1) {
vector<int>res(sz);
iota(res.begin(),res.end(),0);
if(r < 0) r = n;
if(r <= a || b <= l) return res;
if(a <= l && r <= b) return node[k];
auto vl = get(a, b,sz, 2*k+1, l, (l+r)/2);
auto vr= get(a, b,sz, 2*k+2, (l+r)/2, r);
res=comp(vl,vr);
return res;
}
};
void solve(){
int n,m,q;
cin>>n>>m>>q;
SegmentTree seg(m,n);
rep(Q,q){
int t;
cin>>t;
if(t==1){
int d;
cin>>d;d--;
vector<int>p(n);
rep(j,n){cin>>p[j];p[j]--;}
seg.update(d,p);
}
if(t==2){
int s;
cin>>s;
vector<int>p=seg.get(0,s,n);
vector<int>res(n);
rep(j,n){res[p[j]]=j;}
rep(j,n){printf("%d%c",res[j]+1,(j==n-1?'\n':' '));}
}
if(t==3){
int l,r;
cin>>l>>r;
vector<int> p=seg.get(l-1,r,n);
int ans=0;
rep(j,n){
ans+=abs(p[j]-j);
}
cout<<ans<<endl;
}
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
return 0;
}