Submission #995210
Source Code Expand
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <limits>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<int,int>
#define x first
#define y second
#define sf scanf
#define pf printf
#define vec vector
#define pb push_back
#define mp make_pair
#define sz(a) int(a.size())
#define all(a) a.begin(),a.end()
#define clr(a,b) memset(a,b,sizeof(a))
#define bin_cnt(x) __builtin_popcount(x)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define srep(sub,s) for(int sub=s&(s-1);sub;sub=(sub-1)&s)
#define irep(i,a) for(__typeof(a.begin()) i=a.begin();i!=a.end();i++)
#define irrep(i,a) for(__typeof(a.rbegin()) i=a.rbegin();i!=a.rend();i++)
#define inf numeric_limits<int>::max()
#define finf numeric_limits<double>::infinity()
#define eps 1e-8
#pragma GCC optimize ("O3")
#define o3 __attribute__((optimize("O3")))
#pragma comment(linker, "/STACK:32505856")
template<class T> inline T sqr(T a) {return a*a;}
template<class T> inline int gmin(T&a,T b) {if(a>b){a=b;return 1;}return 0;}
template<class T> inline int gmax(T&a,T b) {if(a<b){a=b;return 1;}return 0;}
inline int dcmp(const double &a) {return a>eps?1:(a<-eps?-1:0);}
struct Initializer{Initializer(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}}initializer;
#define N 2000010
int n, m, a[N];
int pos1, pos2, sum1, sum2;
int sum[N];
#define T 4000020
#define idx(l,r) ((l+r)|(l!=r))
int maxv[T], tpos[T];
int P, Q, V, NP;
int base;
void insert(int l, int r) {
int x = idx(l, r);
if (l == r) {
maxv[x] = V;
return;
}
int m = l + r >> 1;
int lx = idx(l, m);
int rx = idx(m + 1, r);
if (P <= m) insert(l, m);
else insert(m + 1, r);
maxv[x] = maxv[lx];
tpos[x] = tpos[lx];
if (gmax(maxv[x], maxv[rx])) tpos[x] = tpos[rx];
}
void select(int l, int r) {
int x = idx(l, r);
if (P <= l && r <= Q) {
if (gmax(V, maxv[x])) {
NP = tpos[x];
}
return;
}
int m = l + r >> 1;
if (P<=m) select(l, m);
if (Q> m) select(m + 1, r);
}
int main() {
// freopen("in.txt","r",stdin);
sf("%d", &n);
int n2 = 2 * n;
rep(i, 0, n2) {
maxv[i] = -inf;
}
rep(i, 1, n - 1) {
sf("%d", a + i);
sum[i] = a[i] + sum[i - 1];
P = i;
V = a[i] - (sum[i] - sum[2]);
insert(1, n);
}
sf("%d", &m);
// pf("%d %d\n",pos1 + pos2 , n + n - 1);
rep(i, 1, m) {
sf("%d", a + n);
sum[n] = a[n] + sum[n - 1];
pos1 = 1;
pos2 = 2;
sum1 = a[1];
sum2 = a[2];
while (pos1 + pos2 < n + n - 1) {
pf("[%d,%d]\n",pos1,pos2);
if (pos1 < pos2) {
P = pos2 + 1,
Q = n,
V = -inf,
NP = pos2 + 1;
select(1, n);
pos1 = NP;
sum1 += V - base;
base += sum[NP] - sum[pos2];
} else {
P = pos1 + 1,
Q = n,
V = -inf,
NP = pos1 + 1;
select(1, n);
pos2 = NP;
sum2 += V - base;
base += sum[NP] - sum[pos1];
}
}
pf("%d\n", sum1 - sum2);
}
return 0;
}
Submission Info
Submission Time |
|
Task |
H - Tokaido |
User |
alpc104 |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
3618 Byte |
Status |
WA |
Exec Time |
2102 ms |
Memory |
86016 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:94:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
sf("%d", &n);
^
./Main.cpp:100:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
sf("%d", a + i);
^
./Main.cpp:106:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
sf("%d", &m);
^
./Main.cpp:109:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
sf("%d", a + n);
^
Judge Result
Set Name |
sample |
dataset1 |
dataset2 |
Score / Max Score |
0 / 0 |
0 / 700 |
0 / 900 |
Status |
|
|
|
Set Name |
Test Cases |
sample |
sample-01.txt, sample-02.txt |
dataset1 |
sample-01.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt |
dataset2 |
sample-01.txt, sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, 02-10.txt, 02-11.txt, 02-12.txt, 02-13.txt, 02-14.txt, 02-15.txt, 02-16.txt |
Case Name |
Status |
Exec Time |
Memory |
01-01.txt |
TLE |
2102 ms |
62848 KB |
01-02.txt |
WA |
3 ms |
256 KB |
01-03.txt |
TLE |
2102 ms |
68352 KB |
01-04.txt |
TLE |
2102 ms |
61312 KB |
01-05.txt |
TLE |
2102 ms |
62336 KB |
01-06.txt |
TLE |
2102 ms |
62848 KB |
01-07.txt |
TLE |
2102 ms |
61568 KB |
01-08.txt |
TLE |
2102 ms |
62592 KB |
01-09.txt |
TLE |
2102 ms |
62848 KB |
01-10.txt |
TLE |
2102 ms |
79744 KB |
01-11.txt |
TLE |
2102 ms |
61696 KB |
01-12.txt |
TLE |
2102 ms |
62592 KB |
01-13.txt |
TLE |
2102 ms |
62848 KB |
01-14.txt |
TLE |
2102 ms |
62464 KB |
01-15.txt |
TLE |
2102 ms |
62848 KB |
01-16.txt |
TLE |
2102 ms |
62464 KB |
01-17.txt |
TLE |
2102 ms |
62592 KB |
01-18.txt |
TLE |
2102 ms |
62848 KB |
01-19.txt |
TLE |
2102 ms |
62848 KB |
02-01.txt |
TLE |
2102 ms |
61696 KB |
02-02.txt |
TLE |
2102 ms |
62592 KB |
02-03.txt |
TLE |
2102 ms |
62720 KB |
02-04.txt |
TLE |
2102 ms |
62720 KB |
02-05.txt |
TLE |
2102 ms |
68480 KB |
02-06.txt |
TLE |
2102 ms |
62592 KB |
02-07.txt |
TLE |
2102 ms |
62464 KB |
02-08.txt |
TLE |
2102 ms |
77440 KB |
02-09.txt |
TLE |
2102 ms |
68352 KB |
02-10.txt |
TLE |
2102 ms |
61312 KB |
02-11.txt |
TLE |
2102 ms |
62720 KB |
02-12.txt |
TLE |
2102 ms |
62720 KB |
02-13.txt |
TLE |
2102 ms |
62848 KB |
02-14.txt |
TLE |
2102 ms |
62592 KB |
02-15.txt |
TLE |
2102 ms |
62848 KB |
02-16.txt |
TLE |
2102 ms |
62208 KB |
sample-01.txt |
TLE |
2102 ms |
86016 KB |
sample-02.txt |
TLE |
2102 ms |
80640 KB |