#include "elephants.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define vc vector
typedef vc<ll> vcll;
typedef vc<bool> vcb;
#define pr pair
typedef pr<ll, ll> prll;
typedef set<ll> setll;
typedef map<ll,ll> mapll;
#define uset unordered_set
typedef uset<ll> usetll;
#define umap unordered_map
typedef umap<ll,ll> umapll;
#define f0r(i,a,n) for ((i)=(a); (i)<=(n); (i)++)
#define r0f(i,n,a) for ((i)=(n); (i)>=(a); (i)--)
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mp make_pair
#define fi first
#define se second
#define sz size
#define all(x) (x).begin(), (x).end()
#define all0(x, n) (x).begin(), (x).begin()+n
#define all1(x, n) (x).begin()+1, (x).begin()+n+1
#define allrev(x) (x).rbegin(), (x).rend()
#define in(v, s) ((s).find((v)) != (s).end())
#define GCD(x, y) __gcd(abs((x)), abs((y)))
#define INF (LLONG_MAX>>3ll)
#define MOD (1'000'000'007ll)
#define mxN (150'010ll)
inline void maxa(ll &a, ll b) { if (a<b) a=b; }
inline void mina(ll &a, ll b) { if (a>b) a=b; }
inline void print (vcll &a, ll n=-1, string name="")
{
cout << name << ": ";
if (n==-1) for (ll x:a) printf("%lli ", x);
else
{
ll i;
f0r(i,1,n) printf("%lli ", a[i]);
}
printf("\n");
}
ll n, L;
vcll ar(mxN);
mapll nums;
inline void del (ll x) { if ((--nums[x]) == 0) nums.erase(x); }
inline void ins (ll x)
{
if (in(x,nums)) nums[x]++;
else nums[x]=1;
}
inline ll calc()
{
ll c=0, last=-INF;
for (prll xc:nums)
{
ll x=xc.fi;
if (x-last > L)
{
last=x;
c++;
}
}
return c;
}
void init (int N, int l, int *X)
{
n=N; L=l;
ll i;
f0r(i,0,n-1) ins(ar[i+1] = X[i]);
}
int update (int i, int x)
{
i++;
del(ar[i]);
ins(ar[i]=x);
return calc();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
7768 KB |
Output is correct |
2 |
Correct |
1 ms |
7772 KB |
Output is correct |
3 |
Correct |
1 ms |
7772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
7768 KB |
Output is correct |
2 |
Correct |
1 ms |
7772 KB |
Output is correct |
3 |
Correct |
1 ms |
7772 KB |
Output is correct |
4 |
Correct |
2 ms |
7772 KB |
Output is correct |
5 |
Correct |
1 ms |
7772 KB |
Output is correct |
6 |
Correct |
1 ms |
7772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
7768 KB |
Output is correct |
2 |
Correct |
1 ms |
7772 KB |
Output is correct |
3 |
Correct |
1 ms |
7772 KB |
Output is correct |
4 |
Correct |
2 ms |
7772 KB |
Output is correct |
5 |
Correct |
1 ms |
7772 KB |
Output is correct |
6 |
Correct |
1 ms |
7772 KB |
Output is correct |
7 |
Correct |
7167 ms |
11612 KB |
Output is correct |
8 |
Execution timed out |
9049 ms |
11868 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
7768 KB |
Output is correct |
2 |
Correct |
1 ms |
7772 KB |
Output is correct |
3 |
Correct |
1 ms |
7772 KB |
Output is correct |
4 |
Correct |
2 ms |
7772 KB |
Output is correct |
5 |
Correct |
1 ms |
7772 KB |
Output is correct |
6 |
Correct |
1 ms |
7772 KB |
Output is correct |
7 |
Correct |
7167 ms |
11612 KB |
Output is correct |
8 |
Execution timed out |
9049 ms |
11868 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
7768 KB |
Output is correct |
2 |
Correct |
1 ms |
7772 KB |
Output is correct |
3 |
Correct |
1 ms |
7772 KB |
Output is correct |
4 |
Correct |
2 ms |
7772 KB |
Output is correct |
5 |
Correct |
1 ms |
7772 KB |
Output is correct |
6 |
Correct |
1 ms |
7772 KB |
Output is correct |
7 |
Correct |
7167 ms |
11612 KB |
Output is correct |
8 |
Execution timed out |
9049 ms |
11868 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |