Submission #2763701
Source Code Expand
#include<set> #include<iostream> #define rep(i,a,b)for(int i=a;i<b;++i) typedef long long ll; using namespace std; int N,Q; ll A[200001],B[200001]; multiset<ll>S; int main(){ ios::sync_with_stdio(0); cin>>N>>Q; rep(i,0,N<<1)cin>>A[i]; rep(i,0,N<<1)cin>>B[i]; ll ans=0; bool odd=0; ans+=A[0]+A[(n<<1)-1]; rep(i,1,(N<<1)-1){ ans+=max(A[i],B[i]); odd^=(A[i]>B[i]); S.insert(abs(A[i]-B[i])); } while(Q--){ ll a,x,y; cin>>a>>x>>y; if(--a==0||a==(N<<1)-1){ ans+=x-A[a]; A[a]=x; }else{ odd^=(A[a]>B[a]); odd^=(x>y); ans+=max(x, y)-max(A[a],B[a]); int*p=S.lower_bound(abs(A[a]-B[a])); S.erase(); S.insert(abs(x-y)); A[a]=x; B[a]=y; } cout<<(!odd?ans:ans-(*S.begin()))<<"\n"; } return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - Paired Parentheses |
User | wessshi |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 782 Byte |
Status | CE |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:17:15: error: ‘n’ was not declared in this scope ans+=A[0]+A[(n<<1)-1]; ^ ./Main.cpp:33:38: error: cannot convert ‘std::multiset<long long int>::iterator {aka std::_Rb_tree_const_iterator<long long int>}’ to ‘int*’ in initialization int*p=S.lower_bound(abs(A[a]-B[a])); ^ ./Main.cpp:34:12: error: no matching function for call to ‘std::multiset<long long int>::erase()’ S.erase(); ^ In file included from /usr/include/c++/5/set:62:0, from ./Main.cpp:1: /usr/include/c++/5/bits/stl_multiset.h:558:7: note: candidate: std::multiset<_Key, _Compare, _Alloc>::iterator std::multiset<_Key, _Compare, _Alloc>::erase(std::multiset<_Key, _Compare, _Alloc>::const_iterator) [with _Key = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<long long int>; std::multiset<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree_const_iterator<long long int>; std::multiset<_K...