結果

問題 No.1386 Range add Simulation
ユーザー 👑 kmjpkmjp
提出日時 2021-02-11 12:48:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 651 ms / 2,000 ms
コード長 2,087 bytes
コンパイル時間 3,084 ms
コンパイル使用メモリ 204,980 KB
実行使用メモリ 26,756 KB
最終ジャッジ日時 2023-09-25 01:52:16
合計ジャッジ時間 39,312 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 4 ms
4,380 KB
testcase_02 AC 4 ms
4,380 KB
testcase_03 AC 5 ms
4,380 KB
testcase_04 AC 4 ms
4,380 KB
testcase_05 AC 5 ms
4,380 KB
testcase_06 AC 291 ms
14,424 KB
testcase_07 AC 294 ms
14,248 KB
testcase_08 AC 291 ms
14,392 KB
testcase_09 AC 290 ms
14,100 KB
testcase_10 AC 295 ms
14,244 KB
testcase_11 AC 579 ms
25,132 KB
testcase_12 AC 586 ms
25,364 KB
testcase_13 AC 580 ms
25,396 KB
testcase_14 AC 589 ms
25,208 KB
testcase_15 AC 579 ms
25,392 KB
testcase_16 AC 580 ms
25,200 KB
testcase_17 AC 581 ms
25,072 KB
testcase_18 AC 586 ms
25,212 KB
testcase_19 AC 578 ms
25,080 KB
testcase_20 AC 582 ms
25,132 KB
testcase_21 AC 594 ms
25,220 KB
testcase_22 AC 580 ms
25,080 KB
testcase_23 AC 585 ms
25,256 KB
testcase_24 AC 588 ms
25,208 KB
testcase_25 AC 587 ms
25,164 KB
testcase_26 AC 582 ms
25,220 KB
testcase_27 AC 590 ms
25,204 KB
testcase_28 AC 584 ms
25,080 KB
testcase_29 AC 584 ms
25,152 KB
testcase_30 AC 586 ms
25,224 KB
testcase_31 AC 630 ms
26,580 KB
testcase_32 AC 630 ms
26,500 KB
testcase_33 AC 651 ms
26,568 KB
testcase_34 AC 625 ms
26,500 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 5 ms
4,376 KB
testcase_37 AC 6 ms
4,376 KB
testcase_38 AC 6 ms
4,380 KB
testcase_39 AC 5 ms
4,380 KB
testcase_40 AC 635 ms
26,432 KB
testcase_41 AC 626 ms
26,576 KB
testcase_42 AC 630 ms
26,512 KB
testcase_43 AC 624 ms
26,724 KB
testcase_44 AC 629 ms
26,444 KB
testcase_45 AC 623 ms
26,436 KB
testcase_46 AC 637 ms
26,580 KB
testcase_47 AC 631 ms
26,440 KB
testcase_48 AC 632 ms
26,756 KB
testcase_49 AC 638 ms
26,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N,Q;
ll V[101010];
ll A[101010];
ll B[101010];


vector<vector<int>> R;

void dfs(int cur,ll v) {
	if(v==0) return;
	if(v/2) {
		dfs(cur,v/2);
		B[cur]*=2;
		R.push_back({3,cur,cur});
	}
	if(v%2) {
		if(v>0) R.push_back({1,cur}), B[cur]++;
		else R.push_back({2,cur}), B[cur]--;
	}
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>Q;
	FOR(i,Q) {
		cin>>x>>y;
		if(x==1) {
			if(y==1) {
				V[1]++;
				V[2]+=3;
				V[3]+=2;
			}
			else if(y==2) {
				V[2]++;
				V[3]+=2;
			}
			else {
				V[y]++;
				V[y+1]++;
			}
			//for(j=y;j<=N;j++) A[j]+=1LL*(j-y+1)*(j-y+1);
		}
		else {
			V[1]+=1LL*y*y;
			V[2]-=2*y-1;
			V[3]+=2;
			V[y+2]--;
			V[y+3]--;
			//for(j=1;j<=y;j++) A[j]+=1LL*(j-y+1)*(j-y+1);
		}
	}
	//cout<<"S1 "; FOR(i,N) cout<<A[i+1]<<" "; cout<<endl;
	for(i=1;i<=N;i++) dfs(i,V[i]);
	//cout<<"S1 ";FOR(i,N) cout<<B[i+1]<<" ";	cout<<endl;
	for(i=3;i<N;i++) R.push_back({3,i+1,i}), B[i+1]+=B[i];
	//cout<<"S1 ";FOR(i,N) cout<<B[i+1]<<" ";	cout<<endl;
	for(i=2;i<N;i++) R.push_back({3,i+1,i}), B[i+1]+=B[i];
	//cout<<"S1 ";FOR(i,N) cout<<B[i+1]<<" ";	cout<<endl;
	for(i=1;i<N;i++) R.push_back({3,i+1,i}), B[i+1]+=B[i];
	//cout<<"S1 ";FOR(i,N) cout<<B[i+1]<<" ";	cout<<endl;
	cout<<R.size()<<endl;
	FORR(r,R) {
		FORR(v,r) cout<<v<<" ";
		cout<<endl;
	}
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0