結果

問題 No.1290 Addition and Subtraction Operation
ユーザー kotatsugamekotatsugame
提出日時 2020-11-13 22:55:04
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 147 ms / 2,000 ms
コード長 2,248 bytes
コンパイル時間 1,064 ms
コンパイル使用メモリ 89,920 KB
実行使用メモリ 14,360 KB
最終ジャッジ日時 2023-09-30 03:55:58
合計ジャッジ時間 6,685 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,928 KB
testcase_01 AC 2 ms
6,900 KB
testcase_02 AC 2 ms
6,936 KB
testcase_03 AC 2 ms
6,996 KB
testcase_04 AC 2 ms
6,892 KB
testcase_05 AC 3 ms
7,052 KB
testcase_06 AC 3 ms
6,936 KB
testcase_07 AC 3 ms
7,172 KB
testcase_08 AC 3 ms
6,896 KB
testcase_09 AC 2 ms
6,996 KB
testcase_10 AC 2 ms
7,044 KB
testcase_11 AC 2 ms
6,876 KB
testcase_12 AC 2 ms
7,004 KB
testcase_13 AC 3 ms
6,904 KB
testcase_14 AC 3 ms
6,896 KB
testcase_15 AC 2 ms
7,032 KB
testcase_16 AC 2 ms
6,884 KB
testcase_17 AC 3 ms
6,892 KB
testcase_18 AC 2 ms
6,904 KB
testcase_19 AC 3 ms
6,900 KB
testcase_20 AC 3 ms
6,948 KB
testcase_21 AC 2 ms
6,988 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,936 KB
testcase_24 AC 2 ms
7,084 KB
testcase_25 AC 2 ms
7,012 KB
testcase_26 AC 2 ms
6,920 KB
testcase_27 AC 2 ms
6,936 KB
testcase_28 AC 3 ms
7,000 KB
testcase_29 AC 3 ms
6,952 KB
testcase_30 AC 2 ms
7,180 KB
testcase_31 AC 2 ms
6,992 KB
testcase_32 AC 2 ms
6,956 KB
testcase_33 AC 2 ms
6,876 KB
testcase_34 AC 2 ms
7,184 KB
testcase_35 AC 3 ms
6,872 KB
testcase_36 AC 2 ms
6,904 KB
testcase_37 AC 2 ms
7,056 KB
testcase_38 AC 2 ms
6,944 KB
testcase_39 AC 2 ms
6,980 KB
testcase_40 AC 2 ms
6,948 KB
testcase_41 AC 2 ms
6,924 KB
testcase_42 AC 40 ms
7,824 KB
testcase_43 AC 41 ms
7,856 KB
testcase_44 AC 40 ms
7,796 KB
testcase_45 AC 40 ms
7,908 KB
testcase_46 AC 41 ms
7,928 KB
testcase_47 AC 42 ms
7,856 KB
testcase_48 AC 42 ms
7,800 KB
testcase_49 AC 40 ms
7,884 KB
testcase_50 AC 42 ms
7,860 KB
testcase_51 AC 40 ms
7,868 KB
testcase_52 AC 41 ms
7,844 KB
testcase_53 AC 42 ms
7,820 KB
testcase_54 AC 43 ms
7,800 KB
testcase_55 AC 41 ms
7,856 KB
testcase_56 AC 40 ms
7,836 KB
testcase_57 AC 33 ms
10,852 KB
testcase_58 AC 44 ms
11,376 KB
testcase_59 AC 36 ms
11,032 KB
testcase_60 AC 87 ms
14,096 KB
testcase_61 AC 63 ms
12,756 KB
testcase_62 AC 69 ms
13,032 KB
testcase_63 AC 43 ms
11,428 KB
testcase_64 AC 20 ms
10,112 KB
testcase_65 AC 26 ms
10,652 KB
testcase_66 AC 52 ms
11,984 KB
testcase_67 AC 90 ms
14,360 KB
testcase_68 AC 64 ms
12,816 KB
testcase_69 AC 44 ms
11,576 KB
testcase_70 AC 39 ms
11,112 KB
testcase_71 AC 48 ms
11,764 KB
testcase_72 AC 27 ms
10,580 KB
testcase_73 AC 60 ms
12,216 KB
testcase_74 AC 19 ms
10,068 KB
testcase_75 AC 24 ms
10,332 KB
testcase_76 AC 40 ms
11,156 KB
testcase_77 AC 130 ms
12,848 KB
testcase_78 AC 116 ms
12,204 KB
testcase_79 AC 81 ms
11,152 KB
testcase_80 AC 147 ms
14,216 KB
testcase_81 AC 145 ms
13,760 KB
testcase_82 AC 68 ms
11,636 KB
testcase_83 AC 100 ms
13,752 KB
testcase_84 AC 91 ms
13,276 KB
testcase_85 AC 48 ms
10,580 KB
testcase_86 AC 39 ms
10,396 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
a.cpp:10:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]

ソースコード

diff #

#line 1 "a.cpp"
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#line 2 "/home/kotatsugame/library/datastructure/dualsegtree.cpp"
#include<functional>
template<typename T>
struct dualsegtree{
	using F=function<T(T,T)>;
	const F lazycalcfn,updatefn;
	int n;
	T lazydefvalue;
	vector<T>dat,lazy;
	vector<bool>lazyflag;
	dualsegtree(int n_=0,T defvalue=0,
		const F lazycalcfn_=[](T a,T b){return a+b;},
		const F updatefn_=[](T a,T b){return a+b;},
		T lazydefvalue_=0
	):lazydefvalue(lazydefvalue_),
		lazycalcfn(lazycalcfn_),updatefn(updatefn_)
	{
		n=1;
		while(n<n_)n<<=1;
		dat.assign(n,defvalue);
		lazy.assign(n-1,lazydefvalue);
		lazyflag.assign(n-1,false);
	}
	void copy(const vector<T>&v)
	{
		for(int i=0;i<v.size();i++)dat[i]=v[i];
		lazy.assign(n-1,lazydefvalue);
		lazyflag.assign(n-1,false);
	}
	void update(int a,int b,T x,int k=0,int l=0,int r=-1)//[a,b)
	{
		if(r<0)r=n;
		if(b<=l||r<=a)return;
		else if(a<=l&&r<=b)
		{
			if(k<n-1)
			{
				lazy[k]=lazycalcfn(lazy[k],x);
				lazyflag[k]=true;
			}
			else dat[k-n+1]=updatefn(dat[k-n+1],x);
		}
		else
		{
			if(lazyflag[k])
			{
				update(0,n,lazy[k],k*2+1,l,(l+r)/2);
				update(0,n,lazy[k],k*2+2,(l+r)/2,r);
				lazy[k]=lazydefvalue;
				lazyflag[k]=false;
			}
			update(a,b,x,k*2+1,l,(l+r)/2);
			update(a,b,x,k*2+2,(l+r)/2,r);
		}
	}
	T query(int i)
	{
		T ret=dat[i];
		i+=n-1;
		while(i>0)
		{
			i=(i-1)/2;
			if(lazyflag[i])ret=updatefn(ret,lazy[i]);
		}
		return ret;
	}
};
#line 6 "a.cpp"
int N,M;
long B[1<<17];
vector<int>E[1<<17];
int R[1<<17];
main()
{
	cin>>N>>M;
	for(int i=0;i<N;i++)
	{
		cin>>B[i];
		if(i%2)B[i]=-B[i];
		R[i]=-1;
	}
	for(int i=0;i<M;i++)
	{
		int L,R;cin>>L>>R;
		L--;
		E[L].push_back(R);
	}
	for(int i=0;i<N;i++)if(!E[i].empty())
	{
		sort(E[i].begin(),E[i].end());
		R[i]=E[i][0];
		for(int j=1;j<E[i].size();j++)
		{
			int l=E[i][j-1],r=E[i][j];
			if(l<r)
			{
				E[l].push_back(r);
			}
		}
	}
	dualsegtree<long>P(N,0,[](long a,long b){return a+b;},[](long a,long b){return a+b;});
	P.copy(vector<long>(B,B+N));
	for(int i=0;i<N;i++)
	{
		long T=P.query(i);
		if(R[i]==-1)
		{
			if(T!=0)
			{
				cout<<"NO"<<endl;
				return 0;
			}
		}
		else
		{
			P.update(i,R[i],-T);
		}
	}
	cout<<"YES"<<endl;
}
0