#include "happiness.h"
#include <bits/stdc++.h>
#define INF (1ll<<61)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
LL M;
int num=1, lc[20202020], rc[20202020];
LL T[20202020], lz[20202020];
void upd(int id, LL s, LL e, LL ts, LL te, LL v){
if (e < ts || te < s) return;
if (ts <= s && e <= te){
if (ts == te){
if (v < 0){
if (!lz[id]) T[id] += v;
lz[id]++;
}
else{
lz[id]--;
if (!lz[id]) T[id] += v;
}
return;
}
T[id] += v, lz[id] += v;
return;
}
LL m=s+e>>1;
if (!lc[id] && ts <= m) lc[id]=++num, T[num]=INF;
if (!rc[id] && te > m) rc[id]=++num, T[num]=INF;
upd(lc[id], s, m, ts, te, v);
upd(rc[id], m+1, e, ts, te, v);
T[id] = min(T[lc[id]], T[rc[id]]) + lz[id];
}
bool init(int N, long long _M, long long A[]) {
M = _M+3;
T[0]=T[1]=INF;
for (int i=0; i<N; i++){
upd(1, 1, M, A[i]+1, M, A[i]);
upd(1, 1, M, A[i], A[i], -INF-A[i]);
}
return T[1]>=-1;
}
bool is_happy(int e, int N, long long A[]) {
if (e>0){
for (int i=0; i<N; i++){
upd(1, 1, M, A[i]+1, M, A[i]);
upd(1, 1, M, A[i], A[i], -INF-A[i]);
}
}
else{
for (int i=0; i<N; i++){
upd(1, 1, M, A[i]+1, M, -A[i]);
upd(1, 1, M, A[i], A[i], INF+A[i]);
}
}
return T[1]>=-1;
}
Compilation message
happiness.cpp: In function 'void upd(int, LL, LL, LL, LL, LL)':
happiness.cpp:29:8: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
29 | LL m=s+e>>1;
| ~^~
grader.cpp: In function 'int main()':
grader.cpp:16:12: warning: unused variable 'max_code' [-Wunused-variable]
16 | long long max_code;
| ^~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |