Submission #374518
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REPR(i,n) for (int i=(int)(n)-1;i>=0;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
#define tpl(...) make_tuple(__VA_ARGS__)
const int INF = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1);
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};
typedef long long ll;
typedef pair<int,int> pii;
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 (b<a) { a=b; return 1; } return 0; }
template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))>basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>&os,
const C& c){os<<'[';for(auto i=begin(c);i!=end(c);++i)os<<(i==begin(c)?"":" ")<<*i;return os<<']';}
template<class S,class T>ostream&operator<<(ostream &o,const pair<S,T>&t){return o<<'('<<t.first<<','<<t.second<<')';}
template<int N,class Tp>void output(ostream&,const Tp&){}
template<int N,class Tp,class,class ...Ts>void output(ostream &o,const Tp&t){if(N)o<<',';o<<get<N>(t);output<N+1,Tp,Ts...>(o,t);}
template<class ...Ts>ostream&operator<<(ostream&o,const tuple<Ts...>&t){o<<'(';output<0,tuple<Ts...>,Ts...>(o,t);return o<<')';}
template<class T>void output(T t,char z=10){if(t<0)t=-t,putchar(45);int c[20];
int k=0;while(t)c[k++]=t%10,t/=10;for(k||(c[k++]=0);k;)putchar(c[--k]^48);putchar(z);}
template<class T>void outputs(T t){output(t);}
template<class S,class ...T>void outputs(S a,T...t){output(a,32);outputs(t...);}
template<class T>void output(T *a,int n){REP(i,n)cout<<a[i]<<(i!=n-1?',':'\n');}
template<class T>void output(T *a,int n,int m){REP(i,n)output(a[i],m);}
template<class T>bool input(T &t){int n=1,c;for(t=0;!isdigit(c=getchar())&&~c&&c-45;);
if(!~c)return 0;for(c-45&&(n=0,t=c^48);isdigit(c=getchar());)t=10*t+c-48;t=n?-t:t;return 1;}
template<class S,class ...T>bool input(S&a,T&...t){input(a);return input(t...);}
template<class T>bool inputs(T *a, int n) { REP(i,n) if(!input(a[i])) return 0; return 1;}
int main() {
int n;
while(input(n)) {
map<int,int> mp;
multiset<int> S;
REP(i,n) {
int x,a;
input(x,a);
mp[x] = a;
S.insert(a);
}
int Q;
input(Q);
assert(n<=2000 && Q<=2000);
while(Q--) {
int c,y,b;
input(c,y,b);
if (c == 1) {
S.insert(b);
mp[y] = b;
} else {
S.erase(S.find(b));
mp.erase(y);
}
// cout << mp << endl;
// cout << S << endl;
int l1 = min(0,mp.begin()->first);
int l2 = 0;
int lc = mp.begin()->second;
int r1 = max(0,mp.rbegin()->first);
int r2 = 0;
int rc = mp.rbegin()->second;
ll sm1 = 0;
FOR(it, mp) {
sm1 += it->second;
if (it->second != lc) chmin(l2, it->first);
if (it->second != rc) chmax(r2, it->first);
}
int ct = 0;
ll sm2 = 0;
int m = S.size();
ll ans = 1LL<<60;
FOR(it, S) {
ll tmp = (sm1 - (m-ct)*(*it)) + (ct*(*it) - sm2);
ll lft = lc == *it ? l2 : l1;
ll rgt = rc == *it ? r2 : r1;
tmp += min(rgt*2+abs(lft), abs(lft)*2+rgt);
chmin(ans, tmp);
sm1 -= *it;
sm2 += *it;
ct++;
}
output(ans);
}
}
}
Submission Info
| Submission Time |
|
| Task |
J - 看板の塗り替え |
| User |
yuusune |
| Language |
C++11 (GCC 4.9.2) |
| Score |
30 |
| Code Size |
3514 Byte |
| Status |
RE |
| Exec Time |
444 ms |
| Memory |
10152 KiB |
Judge Result
| Set Name |
Subtask |
All |
| Score / Max Score |
30 / 30 |
0 / 270 |
| Status |
|
|
| Set Name |
Test Cases |
| Subtask |
subtask_00.txt, subtask_01.txt, subtask_02.txt, subtask_03.txt, subtask_04.txt, subtask_05.txt, subtask_06.txt, subtask_07.txt, subtask_08.txt, subtask_09.txt, subtask_10.txt, subtask_11.txt, subtask_12.txt, subtask_13.txt, subtask_14.txt, subtask_15.txt, subtask_16.txt, subtask_17.txt, subtask_18.txt, subtask_19.txt, subtask_20.txt, subtask_21.txt, subtask_22.txt, subtask_23.txt, subtask_24.txt, subtask_25.txt |
| All |
scrambled_00.txt, scrambled_01.txt, scrambled_02.txt, scrambled_03.txt, scrambled_04.txt, scrambled_05.txt, scrambled_06.txt, scrambled_07.txt, scrambled_08.txt, scrambled_09.txt, scrambled_10.txt, scrambled_11.txt, scrambled_12.txt, scrambled_13.txt, scrambled_14.txt, scrambled_15.txt, scrambled_16.txt, scrambled_17.txt, scrambled_18.txt, scrambled_19.txt, scrambled_20.txt, scrambled_21.txt, scrambled_22.txt, scrambled_23.txt, scrambled_24.txt, scrambled_25.txt, scrambled_26.txt, subtask_00.txt, subtask_01.txt, subtask_02.txt, subtask_03.txt, subtask_04.txt, subtask_05.txt, subtask_06.txt, subtask_07.txt, subtask_08.txt, subtask_09.txt, subtask_10.txt, subtask_11.txt, subtask_12.txt, subtask_13.txt, subtask_14.txt, subtask_15.txt, subtask_16.txt, subtask_17.txt, subtask_18.txt, subtask_19.txt, subtask_20.txt, subtask_21.txt, subtask_22.txt, subtask_23.txt, subtask_24.txt, subtask_25.txt |
| Case Name |
Status |
Exec Time |
Memory |
| scrambled_00.txt |
AC |
30 ms |
800 KiB |
| scrambled_01.txt |
RE |
417 ms |
10148 KiB |
| scrambled_02.txt |
RE |
320 ms |
3488 KiB |
| scrambled_03.txt |
RE |
355 ms |
6168 KiB |
| scrambled_04.txt |
RE |
320 ms |
3996 KiB |
| scrambled_05.txt |
RE |
407 ms |
9244 KiB |
| scrambled_06.txt |
RE |
421 ms |
10140 KiB |
| scrambled_07.txt |
RE |
293 ms |
2076 KiB |
| scrambled_08.txt |
RE |
412 ms |
9368 KiB |
| scrambled_09.txt |
RE |
344 ms |
6044 KiB |
| scrambled_10.txt |
RE |
342 ms |
4772 KiB |
| scrambled_11.txt |
RE |
427 ms |
10144 KiB |
| scrambled_12.txt |
RE |
439 ms |
9056 KiB |
| scrambled_13.txt |
RE |
316 ms |
2984 KiB |
| scrambled_14.txt |
RE |
444 ms |
8868 KiB |
| scrambled_15.txt |
RE |
318 ms |
3492 KiB |
| scrambled_16.txt |
RE |
400 ms |
10148 KiB |
| scrambled_17.txt |
RE |
337 ms |
6304 KiB |
| scrambled_18.txt |
RE |
313 ms |
3760 KiB |
| scrambled_19.txt |
RE |
300 ms |
3356 KiB |
| scrambled_20.txt |
RE |
303 ms |
3240 KiB |
| scrambled_21.txt |
RE |
416 ms |
10140 KiB |
| scrambled_22.txt |
RE |
416 ms |
10152 KiB |
| scrambled_23.txt |
RE |
300 ms |
2784 KiB |
| scrambled_24.txt |
RE |
377 ms |
8104 KiB |
| scrambled_25.txt |
RE |
349 ms |
5924 KiB |
| scrambled_26.txt |
RE |
294 ms |
1836 KiB |
| subtask_00.txt |
AC |
350 ms |
1064 KiB |
| subtask_01.txt |
AC |
246 ms |
1060 KiB |
| subtask_02.txt |
AC |
107 ms |
932 KiB |
| subtask_03.txt |
AC |
41 ms |
928 KiB |
| subtask_04.txt |
AC |
69 ms |
928 KiB |
| subtask_05.txt |
AC |
105 ms |
932 KiB |
| subtask_06.txt |
AC |
35 ms |
928 KiB |
| subtask_07.txt |
AC |
92 ms |
932 KiB |
| subtask_08.txt |
AC |
25 ms |
932 KiB |
| subtask_09.txt |
AC |
32 ms |
800 KiB |
| subtask_10.txt |
AC |
165 ms |
928 KiB |
| subtask_11.txt |
AC |
26 ms |
928 KiB |
| subtask_12.txt |
AC |
86 ms |
932 KiB |
| subtask_13.txt |
AC |
27 ms |
800 KiB |
| subtask_14.txt |
AC |
30 ms |
736 KiB |
| subtask_15.txt |
AC |
219 ms |
1048 KiB |
| subtask_16.txt |
AC |
83 ms |
932 KiB |
| subtask_17.txt |
AC |
73 ms |
928 KiB |
| subtask_18.txt |
AC |
29 ms |
844 KiB |
| subtask_19.txt |
AC |
158 ms |
856 KiB |
| subtask_20.txt |
AC |
401 ms |
1064 KiB |
| subtask_21.txt |
AC |
226 ms |
936 KiB |
| subtask_22.txt |
AC |
62 ms |
932 KiB |
| subtask_23.txt |
AC |
67 ms |
924 KiB |
| subtask_24.txt |
AC |
32 ms |
924 KiB |
| subtask_25.txt |
AC |
81 ms |
808 KiB |