//
#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define o cout<<"BUG"<<endl;
#define FOR(i, j, n) for(int j = i; j < n; ++j)
#define forn(i, j, n) for(int j = i; j <= n; ++j)
#define nfor(i, j, n) for(int j = n; j >= i; --j)
#define sortv(vv) sort(vv.begin(), vv.end())
#define all(v) v.begin(), v.end()
#define ld long double
#define ull unsigned long long
using namespace std;
const int maxn=1e6+10,LOG=17, mod=1e9+7;
int block = 320, timer = 0;
const ld EPS = 1e-18;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define bt(i) (1 << (i))
#define int ll
const ll inf=1e9+10;
#define y1 yy
#define prev pre
#define pii pair <int, int>
int q, l, ty[maxn], x[maxn], a[maxn], n, sug[maxn], ants[maxn];
vector <int> vec;
map <int, int> mapp;
main()
{
IOS
cin >> q >> l;
forn(1, i, q)
{
cin >> ty[i] >> x[i] >> a[i];
vec.pb(x[i]);
}
sort(all(vec));
vec.erase(unique(all(vec)), vec.end());
n = vec.size();
FOR(0, i, n)
{
mapp[x[i]] = i + 1;
}
forn(1, i, q)
{
x[i] = mapp[x[i]];
}
forn(1, iter, q)
{
if(ty[iter] == 1)
{
ants[x[iter]] += a[iter];
}
else
{
sug[x[iter]] += a[iter];
}
stack <pii> stac;
nfor(1, i, n)
{
if(sug[i]) stac.push({sug[i], i});
}
int ans = 0;
forn(1, i, n)
{
while(stac.size() && stac.top().s < i && vec[i] - vec[stac.top().s] > l)
{
stac.pop();
}
int temp = ants[i];
while(temp && stac.size() && abs(vec[i] - vec[stac.top().s]) <= l)
{
if(stac.top().f < temp)
{
temp -= stac.top().f;
ans += stac.top().f;
stac.pop();
}
else
{
stac.top().f -= temp;
ans += temp;
temp = 0;
}
}
}
cout << ans << "\n";
}
}
Compilation message
sugar.cpp:36:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
36 | main()
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |