結果

問題 No.1558 Derby Live
ユーザー chocoruskchocorusk
提出日時 2021-06-25 22:12:49
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 240 ms / 2,000 ms
コード長 2,617 bytes
コンパイル時間 3,730 ms
コンパイル使用メモリ 195,272 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-09-07 14:35:26
合計ジャッジ時間 12,532 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 201 ms
6,676 KB
testcase_01 AC 240 ms
6,648 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 162 ms
4,376 KB
testcase_04 AC 80 ms
4,380 KB
testcase_05 AC 93 ms
4,376 KB
testcase_06 AC 155 ms
4,376 KB
testcase_07 AC 5 ms
4,376 KB
testcase_08 AC 150 ms
4,956 KB
testcase_09 AC 157 ms
5,476 KB
testcase_10 AC 164 ms
5,400 KB
testcase_11 AC 168 ms
5,612 KB
testcase_12 AC 173 ms
5,536 KB
testcase_13 AC 180 ms
6,072 KB
testcase_14 AC 187 ms
5,976 KB
testcase_15 AC 192 ms
6,076 KB
testcase_16 AC 199 ms
6,132 KB
testcase_17 AC 216 ms
6,536 KB
testcase_18 AC 219 ms
6,500 KB
testcase_19 AC 223 ms
6,664 KB
testcase_20 AC 228 ms
6,608 KB
testcase_21 AC 215 ms
6,652 KB
testcase_22 AC 222 ms
6,540 KB
testcase_23 AC 227 ms
6,452 KB
testcase_24 AC 212 ms
6,540 KB
testcase_25 AC 225 ms
6,460 KB
testcase_26 AC 230 ms
6,516 KB
testcase_27 AC 212 ms
6,584 KB
testcase_28 AC 220 ms
6,456 KB
testcase_29 AC 229 ms
6,512 KB
testcase_30 AC 212 ms
6,664 KB
testcase_31 AC 221 ms
6,496 KB
testcase_32 AC 234 ms
6,648 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,380 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>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
template<typename Monoid>
struct SegmentTree{
	using F=function<Monoid(Monoid, Monoid)>;
	int sz;
	vector<Monoid> seg;
	const F f;
	const Monoid e;

	SegmentTree(int n, const F f, const Monoid &e): f(f), e(e){
		sz=1;
		while(sz<n) sz<<=1;
		seg.resize(2*sz, e);
	}

	SegmentTree(int n, const F f, const Monoid &e, vector<Monoid> v): f(f), e(e){
		sz=1;
		while(sz<n) sz<<=1;
		seg.resize(2*sz, e);
		for(int i=0; i<n; i++) seg[i+sz]=v[i];
		for(int i=sz-1; i>=1; i--){
			seg[i]=f(seg[2*i], seg[2*i+1]);
		}
	}

	void update(int k, const Monoid &x){
		k+=sz;
		seg[k]=x;
		while(k>1){
			k>>=1;
			seg[k]=f(seg[2*k], seg[2*k+1]);
		}
	}

	Monoid query(int a, int b){ //演算が非可換のとき
		a+=sz, b+=sz;
		Monoid retl=e, retr=e;
		for(;a<b; a>>=1, b>>=1){
			if(b&1) retr=f(seg[--b], retr);
			if(a&1) retl=f(retl, seg[a++]);
		}
		return f(retl, retr);
	}

	Monoid operator[](const int &k) const{
		return seg[k+sz];
	}
};
int main()
{
    int n, m, q;
    cin>>n>>m>>q;
    auto f=[&](vector<int> a, vector<int> b){
        vector<int> res(n);
        for(int i=0; i<n; i++) res[i]=b[a[i]];
        return res;
    };
    vector<int> e(n);
    for(int i=0; i<n; i++) e[i]=i;
    SegmentTree<vector<int>> seg(m, f, e);
    while(q--){
        int t; cin>>t;
        if(t==1){
            int d; cin>>d;
            vector<int> p(n);
            for(int i=0; i<n; i++){
                cin>>p[i]; p[i]--;
            }
            seg.update(d-1, p);
        }else if(t==2){
            int s; cin>>s;
            auto p=seg.query(0, s);
            vector<int> ans(n);
            for(int i=0; i<n; i++) ans[p[i]]=i;
            for(int i=0; i<n; i++){
                cout<<ans[i]+1;
                if(i<n-1) cout<<" ";
            }
            cout<<endl;
        }else{
           int l, r;
           cin>>l>>r;
           l--;
           auto p=seg.query(l, r);
           int ans=0;
           for(int i=0; i<n; i++) ans+=abs(i-p[i]);
           cout<<ans<<endl; 
        }
    }
    return 0;
}


0