結果

問題 No.833 かっこいい電車
ユーザー 沙耶花沙耶花
提出日時 2020-12-09 22:21:50
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 988 bytes
コンパイル時間 1,831 ms
コンパイル使用メモリ 202,000 KB
最終ジャッジ日時 2025-01-16 20:59:41
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:20:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   20 |                 scanf("%d",&A);
      |                 ~~~~~^~~~~~~~~
main.cpp:26:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   26 |                 scanf("%d %d",&t,&x);
      |                 ~~~~~^~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/fenwicktree>
using namespace atcoder;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 10000000

int main(){
	
	int N,Q;
	cin>>N>>Q;
	
	map<int,int> mp;
	rep(i,N)mp[i] = i+1;
	
	fenwick_tree<long long> F(N);
	rep(i,N){
		int A;
		scanf("%d",&A);
		F.add(i,A);
	}
	
	rep(i,Q){
		int t,x;
		scanf("%d %d",&t,&x);
		x--;
		auto it = mp.upper_bound(x);
		it--;
		//cout<<(it->first)<<','<<(it->second)<<endl;
		if(t==1){
			if(it->second-1==x){
				int temp = it->first;
				it = mp.erase(it);
				int x = temp;
				int y = it->second;
				mp.erase(it);
				mp[x] = y;
			}
		}
		if(t==2){
			if(it->second-1!=x){
				int a = it->first;
				int b = x+1;
				int c = x+1;
				int d = it->second;
				mp.erase(it);
				mp[a] = b;
				mp[c] = d;
			}
		}
		if(t==3){
			F.add(x,1);
		}
		if(t==4){
			int l = it->first;
			int r = it->second;
			printf("%lld\n",F.sum(l,r));
		}
	}
	
	
    return 0;
}
0