Submission #1004279
Source Code Expand
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <utility>
typedef long long signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(int i = (l) ; i < (r); i++)
#define incII(i, l, r) for(int i = (l) ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r) ; i >= (l); i--)
#define inc( i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec( i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) < (r))
template<typename T> void swap(T & x, T & y) { T t = x; x = y; y = t; return; }
template<typename T> T abs(T x) { return (0 <= x ? x : -x); }
template<typename T> T max(T a, T b) { return (b <= a ? a : b); }
template<typename T> T min(T a, T b) { return (a <= b ? a : b); }
template<typename T> bool setmin(T & a, T b) { if(a <= b) { return false; } else { a = b; return true; } }
template<typename T> bool setmax(T & a, T b) { if(b <= a) { return false; } else { a = b; return true; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
// ---- ----
const int N = 200000;
const int S = 2000001;
int n, a[N], m, x[N];
int total, val[S], ans[S];
int id[S];
std::vector<int> vec[S];
void uf_init() {
inc(i, total * 2) {
id[i] = i;
vec[i].push_back(i);
}
}
int unite(int x, int y) {
int vx = id[x], vy = id[y];
if(vx == vy) { return vx; }
if(vec[vx].size() < vec[vy].size()) { swap(vx, vy); }
for(auto && e : vec[vy]) {
id[e] = vx;
vec[vx].push_back(e);
}
vec[vy].clear();
return vx;
}
int main() {
scanf("%d", &n);
inc(i, n - 1) { scanf("%d", &a[i]); }
scanf("%d", &m);
inc(i, m) { scanf("%d", &x[i]); }
incID(i, 2, n - 1) { total += a[i]; }
uf_init();
int sum = 0;
decID(i, 2, n - 1) {
sum += a[i];
inc1(j, a[i]) {
val[ unite(sum + j, sum - j) ] = sum + j;
}
}
incII(i, 0, sum * 2) {
for(auto && e : vec[i]) {
ans[e] = val[i];
}
}
inc(i, m) {
printf("%d\n", (x[i] < sum ? ans[ x[i] ] : x[i]) - sum - a[1] + a[0]);
}
return 0;
}
Submission Info
Submission Time |
|
Task |
H - Tokaido |
User |
FF256grhy |
Language |
C++14 (GCC 5.4.1) |
Score |
1600 |
Code Size |
2321 Byte |
Status |
AC |
Exec Time |
370 ms |
Memory |
148560 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:64:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
^
./Main.cpp:65:36: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
inc(i, n - 1) { scanf("%d", &a[i]); }
^
./Main.cpp:66:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &m);
^
./Main.cpp:67:32: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
inc(i, m) { scanf("%d", &x[i]); }
^
Judge Result
Set Name |
sample |
dataset1 |
dataset2 |
Score / Max Score |
0 / 0 |
700 / 700 |
900 / 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 |
AC |
310 ms |
138208 KB |
01-02.txt |
AC |
57 ms |
47104 KB |
01-03.txt |
AC |
333 ms |
148300 KB |
01-04.txt |
AC |
307 ms |
140128 KB |
01-05.txt |
AC |
304 ms |
138208 KB |
01-06.txt |
AC |
302 ms |
138208 KB |
01-07.txt |
AC |
314 ms |
141792 KB |
01-08.txt |
AC |
309 ms |
138720 KB |
01-09.txt |
AC |
310 ms |
138720 KB |
01-10.txt |
AC |
289 ms |
129920 KB |
01-11.txt |
AC |
298 ms |
129664 KB |
01-12.txt |
AC |
302 ms |
131696 KB |
01-13.txt |
AC |
301 ms |
130868 KB |
01-14.txt |
AC |
290 ms |
131072 KB |
01-15.txt |
AC |
313 ms |
131052 KB |
01-16.txt |
AC |
288 ms |
129920 KB |
01-17.txt |
AC |
74 ms |
47872 KB |
01-18.txt |
AC |
76 ms |
47872 KB |
01-19.txt |
AC |
74 ms |
47872 KB |
02-01.txt |
AC |
318 ms |
143840 KB |
02-02.txt |
AC |
353 ms |
140896 KB |
02-03.txt |
AC |
346 ms |
139488 KB |
02-04.txt |
AC |
345 ms |
139360 KB |
02-05.txt |
AC |
370 ms |
148560 KB |
02-06.txt |
AC |
350 ms |
139872 KB |
02-07.txt |
AC |
350 ms |
140128 KB |
02-08.txt |
AC |
327 ms |
130944 KB |
02-09.txt |
AC |
328 ms |
130304 KB |
02-10.txt |
AC |
348 ms |
132408 KB |
02-11.txt |
AC |
347 ms |
133748 KB |
02-12.txt |
AC |
344 ms |
133240 KB |
02-13.txt |
AC |
334 ms |
133276 KB |
02-14.txt |
AC |
330 ms |
132096 KB |
02-15.txt |
AC |
115 ms |
50176 KB |
02-16.txt |
AC |
113 ms |
50176 KB |
sample-01.txt |
AC |
58 ms |
47104 KB |
sample-02.txt |
AC |
58 ms |
47104 KB |