# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1048304 |
2024-08-08T06:35:25 Z |
fgbdvcs |
Meteors (POI11_met) |
C++14 |
|
934 ms |
33852 KB |
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define int long long
int const maxn = 3e5+7;
const ll INF = LLONG_MAX;
int n , m , q;
int x[maxn] ;
int l[maxn] , r[maxn];
int le[maxn] , ri[maxn];
ll v[maxn] , a[maxn];
vector<int> adj[maxn];
vector<int> stage , temp;
struct Fw
{
ll bit[maxn];
Fw()
{
memset(bit , 0 , sizeof(bit));
}
void Clear()
{
memset(bit , 0 , sizeof(bit));
}
void Upd(int u , ll v)
{
int idx = u;
while(idx <= m){
bit[idx] += v;
idx += (idx & (- idx));
}
}
ll Get(int u)
{
ll re = 0;
int idx = u;
while(idx){
re += bit[idx];
idx -= (idx & (- idx));
}
return re;
}
};
Fw Fen;
void Update(int pos)
{
Fen.Upd(l[pos] , v[pos]);
Fen.Upd(r[pos] + 1 , - v[pos]);
if(l[pos] > r[pos]){
Fen.Upd(1 , v[pos]);
}
}
ll Get_sum(int pos)
{
ll re = 0;
for(auto u : adj[pos]){
re += Fen.Get(u);
}
return re;
}
void Input()
{
cin >> n >> m;
for(int i = 1 ; i <= m ; i ++){
cin >> x[i];
adj[x[i]].pb(i);
}
for(int i = 1 ; i <= n ; i ++){
cin >> a[i];
}
cin >> q;
for(int i = 1 ; i <= q ; i ++){
cin >> l[i] >> r[i] >> v[i];
}
}
bool cmp(int x , int y)
{
return (le[x] + ri[x]) / 2 < (le[y] + ri[y]) / 2;
}
void Solve()
{
for(int i = 1 ; i <= n ; i ++){
stage.pb(i);
le[i] = 1;
ri[i] = q;
}
while(stage.size() != 0){
sort(stage.begin() , stage.end() , cmp);
int run = 1;
for(auto u : stage){
int mid = (le[u] + ri[u]) / 2;
while(run <= mid){
Update(run);
run ++;
}
ll s = Get_sum(u);
if(s < a[u]) le[u] = mid + 1;
else ri[u] = mid - 1;
if(le[u] <= ri[u]) temp.pb(u);
}
// cout << "Check " << "\n";
// for(int i = 1 ; i <= n ; i ++){
// cout << le[i] << " " << ri[i] << "\n";
// }
swap(stage , temp);
temp.clear();
Fen.Clear();
}
for(int i = 1 ; i <= n ; i ++){
// cout << "le " << le[i] << "\n";
le[i] > q ? cout << "NIE" : cout << le[i];
cout << "\n";
}
}
signed main()
{
// freopen(".INP","r",stdin);
// freopen(".OUT","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int tt = 1;
//cin >> tt;
while(tt--){
Input();
Solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
23128 KB |
Output is correct |
2 |
Correct |
3 ms |
23132 KB |
Output is correct |
3 |
Correct |
3 ms |
23240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
23132 KB |
Output is correct |
2 |
Correct |
3 ms |
23132 KB |
Output is correct |
3 |
Correct |
4 ms |
23264 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
23944 KB |
Output is correct |
2 |
Correct |
84 ms |
26704 KB |
Output is correct |
3 |
Correct |
57 ms |
24328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
24152 KB |
Output is correct |
2 |
Correct |
61 ms |
24152 KB |
Output is correct |
3 |
Correct |
94 ms |
26672 KB |
Output is correct |
4 |
Correct |
22 ms |
24280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
23900 KB |
Output is correct |
2 |
Correct |
64 ms |
26592 KB |
Output is correct |
3 |
Correct |
14 ms |
23128 KB |
Output is correct |
4 |
Correct |
60 ms |
24540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
23512 KB |
Output is correct |
2 |
Correct |
78 ms |
24024 KB |
Output is correct |
3 |
Correct |
41 ms |
23772 KB |
Output is correct |
4 |
Correct |
88 ms |
26720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
934 ms |
33852 KB |
Output is correct |
2 |
Incorrect |
564 ms |
26712 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
898 ms |
33480 KB |
Output is correct |
2 |
Incorrect |
489 ms |
26580 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |