# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1081860 |
2024-08-30T12:10:47 Z |
FIFI_cpp |
Snowball (JOI21_ho_t2) |
C++17 |
|
153 ms |
20196 KB |
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <fstream>
#include <iterator>
#include <set>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <cctype>
#include <string>
#include <cassert>
#include <set>
#include <bitset>
#include <unordered_set>
#include <numeric>
//using ll = int64_t;
#define pb push_back
#define all(a) a.begin(),a.end()
#define ppi pair<int,pair<int,int>>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int int64_t
// xcode cant include bits/stdc++.h
using namespace std;
/* /\_/\
* (= ._.)
* / > \>
*/
// encouraging cat
const int INF = 1000000;
const int mod = 1000000007;
const int MAXN = 2e5+5;
int n,q;
int pre1[MAXN + 1],pre2[MAXN + 1];
bool check(int k,int tmp)
{
return ((pre1[k]+pre2[k])<=tmp);
}
int32_t main()
{
cin >> n >> q;
vector<int> x(MAXN + 1),a(MAXN + 1),w(MAXN + 1),sum(MAXN + 1);
vector<pair<int,int>> b(n + 1);
for(int i = 1;i <= n;i++)
{
cin >> x[i];
}
for(int i = 1;i <= q;i++)
{
cin >> w[i];
}
sum[0] = 0;
pre1[0] = pre2[0] = 0;
for(int j = 1;j <= q;j++)
{
sum[j] = sum[j-1] + w[j];
pre1[j] = max(pre1[j - 1],sum[j]);
pre2[j] = max(pre2[j - 1],-sum[j]);
}
a[1] = pre2[q];
a[n] = pre1[q];
for(int i = 1;i < n;i++)
{
int tmp = x[i + 1] - x[i];
int l = 1,r = q,res=0;
while(l <= r)
{
int mid = (l + r) / 2;
if(check(mid,tmp))
{
res = mid;
l = mid+1;
}
else
r = mid-1;
}
if(res > 0)
{
b[i].first = pre1[res];
b[i].second = pre2[res];
}
if(res < q)
{
int pre_l = b[i].first,pre_r = b[i].second;
int cur = tmp - pre_l - pre_r;
if(sum[res + 1] > 0)
{
b[i].first += cur;
}
else
b[i].second+=cur;
}
}
for(int i = 1;i <= n;i++)
{
if(i < n)
{
a[i] += b[i].first;
a[i+1] += b[i].second;
}
cout << a[i] << '\n';
}
return 0;
}
Compilation message
Main.cpp:31:9: warning: "/*" within comment [-Wcomment]
31 | /* /\_/\
|
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
6748 KB |
Output is correct |
2 |
Correct |
3 ms |
6748 KB |
Output is correct |
3 |
Correct |
4 ms |
6744 KB |
Output is correct |
4 |
Correct |
4 ms |
6748 KB |
Output is correct |
5 |
Correct |
4 ms |
6744 KB |
Output is correct |
6 |
Correct |
4 ms |
6748 KB |
Output is correct |
7 |
Correct |
4 ms |
6748 KB |
Output is correct |
8 |
Correct |
4 ms |
6744 KB |
Output is correct |
9 |
Correct |
4 ms |
6748 KB |
Output is correct |
10 |
Correct |
4 ms |
6748 KB |
Output is correct |
11 |
Correct |
3 ms |
6748 KB |
Output is correct |
12 |
Correct |
3 ms |
6492 KB |
Output is correct |
13 |
Correct |
3 ms |
6492 KB |
Output is correct |
14 |
Correct |
3 ms |
6628 KB |
Output is correct |
15 |
Correct |
4 ms |
6796 KB |
Output is correct |
16 |
Correct |
4 ms |
6748 KB |
Output is correct |
17 |
Correct |
4 ms |
6748 KB |
Output is correct |
18 |
Correct |
3 ms |
6492 KB |
Output is correct |
19 |
Correct |
4 ms |
6748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
6748 KB |
Output is correct |
2 |
Correct |
3 ms |
6748 KB |
Output is correct |
3 |
Correct |
4 ms |
6744 KB |
Output is correct |
4 |
Correct |
4 ms |
6748 KB |
Output is correct |
5 |
Correct |
4 ms |
6744 KB |
Output is correct |
6 |
Correct |
4 ms |
6748 KB |
Output is correct |
7 |
Correct |
4 ms |
6748 KB |
Output is correct |
8 |
Correct |
4 ms |
6744 KB |
Output is correct |
9 |
Correct |
4 ms |
6748 KB |
Output is correct |
10 |
Correct |
4 ms |
6748 KB |
Output is correct |
11 |
Correct |
3 ms |
6748 KB |
Output is correct |
12 |
Correct |
3 ms |
6492 KB |
Output is correct |
13 |
Correct |
3 ms |
6492 KB |
Output is correct |
14 |
Correct |
3 ms |
6628 KB |
Output is correct |
15 |
Correct |
4 ms |
6796 KB |
Output is correct |
16 |
Correct |
4 ms |
6748 KB |
Output is correct |
17 |
Correct |
4 ms |
6748 KB |
Output is correct |
18 |
Correct |
3 ms |
6492 KB |
Output is correct |
19 |
Correct |
4 ms |
6748 KB |
Output is correct |
20 |
Correct |
62 ms |
11796 KB |
Output is correct |
21 |
Correct |
53 ms |
11684 KB |
Output is correct |
22 |
Correct |
49 ms |
11348 KB |
Output is correct |
23 |
Correct |
56 ms |
11348 KB |
Output is correct |
24 |
Correct |
65 ms |
11856 KB |
Output is correct |
25 |
Correct |
149 ms |
18268 KB |
Output is correct |
26 |
Correct |
153 ms |
18152 KB |
Output is correct |
27 |
Correct |
140 ms |
17748 KB |
Output is correct |
28 |
Correct |
148 ms |
18000 KB |
Output is correct |
29 |
Correct |
140 ms |
17496 KB |
Output is correct |
30 |
Correct |
122 ms |
16720 KB |
Output is correct |
31 |
Correct |
101 ms |
16348 KB |
Output is correct |
32 |
Correct |
104 ms |
16464 KB |
Output is correct |
33 |
Correct |
18 ms |
7768 KB |
Output is correct |
34 |
Correct |
149 ms |
18536 KB |
Output is correct |
35 |
Correct |
148 ms |
17876 KB |
Output is correct |
36 |
Correct |
150 ms |
18256 KB |
Output is correct |
37 |
Correct |
144 ms |
18000 KB |
Output is correct |
38 |
Correct |
140 ms |
17616 KB |
Output is correct |
39 |
Correct |
132 ms |
18008 KB |
Output is correct |
40 |
Correct |
121 ms |
18004 KB |
Output is correct |
41 |
Correct |
69 ms |
12368 KB |
Output is correct |
42 |
Correct |
97 ms |
16464 KB |
Output is correct |
43 |
Correct |
146 ms |
19556 KB |
Output is correct |
44 |
Correct |
69 ms |
12376 KB |
Output is correct |
45 |
Correct |
112 ms |
18000 KB |
Output is correct |
46 |
Correct |
143 ms |
19796 KB |
Output is correct |
47 |
Correct |
145 ms |
20052 KB |
Output is correct |
48 |
Correct |
150 ms |
20196 KB |
Output is correct |