# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
762453 |
2023-06-21T12:10:56 Z |
vjudge1 |
Meteors (POI11_met) |
C++17 |
|
1618 ms |
59360 KB |
//Bismillahir-Rahmanir-Rahim
# include <bits/stdc++.h>
# define pb push_back
# define ff first
# define ss second
# define nl "\n"
# define sz(x) ((int)(x).size())
# define deb(x) cerr << #x << " = " << x << endl;
# define pll pair <ll, ll>
# define pii pair <int, int>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll maxn = 3e5 + 25;
const ll inf = 2e18 + 0;
const ll mod = 1e9 + 7;
const ll dx[] = {-1, 1, 0, 0};
const ll dy[] = {0, 0, -1, 1};
const ll P = 67;
using namespace std;
int n, m, q, tl[maxn], tr[maxn];
vector <int> boss[maxn];
int need[maxn], ans[maxn];
int l[maxn], r[maxn];
ll a[maxn];
vector <int> check[maxn];
struct fenwick
{
ll t[maxn];
void clear ()
{
for (int i = 1; i <= m; ++i)
{
t[i] = 0;
}
}
void update (int id, ll x)
{
for (; id < maxn; id += (id & (-id)))
{
t[id] += x;
}
}
ll get (int id)
{
ll res = 0;
for (; id >= 1; id -= (id & (-id)))
{
res += t[id];
}
return res;
}
} t;
void ma1n (/* SABR */)
{
cin >> n >> m;
for (int i = 1; i <= m; ++i)
{
int owner;
cin >> owner;
boss[owner].pb(i);
}
for (int i = 1; i <= n; ++i)
{
cin >> need[i];
}
cin >> q;
for (int i = 1; i <= q; ++i)
{
cin >> l[i] >> r[i] >> a[i];
}
for (int i = 1; i <= n; ++i)
{
tl[i] = 1, tr[i] = q, ans[i] = -1;
}
bool boo = 1;
while (boo)
{
boo = 0;
t.clear();
for (int i = 1; i <= n; ++i)
{
if (tl[i] <= tr[i])
{
check[(tl[i] + tr[i]) >> 1].pb(i);
}
// cout << tl[i] << ' ' << tr[i] << nl;
}
for (int i = 1; i <= q; ++i)
{
if (l[i] <= r[i])
{
t.update(l[i], a[i]);
t.update(r[i] + 1, -a[i]);
}
else
{
t.update(1, a[i]);
t.update(r[i] + 1, -a[i]);
t.update(l[i], a[i]);
}
while (!check[i].empty())
{
boo = 1;
int id = check[i].back();
check[i].pop_back();
ll sum = 0;
for (int x : boss[id])
{
sum += t.get(x);
if (sum >= need[id]) break;
}
if (sum >= need[id])
{
tr[id] = i - 1;
ans[id] = i;
}
else
{
tl[id] = i + 1;
}
}
}
}
for (int i = 1; i <= n; ++i)
{
if (ans[i] == -1)
{
cout << "NIE" << nl;
}
else
{
cout << ans[i] << nl;
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
// freopen("file.in", "r", stdin);
// freopen("file.out", "w", stdout);
int ttt = 1;
// cin >> ttt;
for (int test = 1; test <= ttt; ++test)
{
// cout << "Case " << test << ":" << '\n';
ma1n();
}
return 0;
}
// 998batrr | BbIWEJI 3A TObOU!!!
// tourist | BbIWEJI 3A TObOU!!!
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
14420 KB |
Output is correct |
2 |
Correct |
8 ms |
14560 KB |
Output is correct |
3 |
Correct |
8 ms |
14548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14548 KB |
Output is correct |
2 |
Correct |
8 ms |
14492 KB |
Output is correct |
3 |
Correct |
7 ms |
14548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
16392 KB |
Output is correct |
2 |
Correct |
122 ms |
18508 KB |
Output is correct |
3 |
Correct |
89 ms |
18024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
96 ms |
17480 KB |
Output is correct |
2 |
Correct |
99 ms |
17520 KB |
Output is correct |
3 |
Correct |
120 ms |
18624 KB |
Output is correct |
4 |
Correct |
31 ms |
16784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
92 ms |
16908 KB |
Output is correct |
2 |
Correct |
143 ms |
19100 KB |
Output is correct |
3 |
Correct |
108 ms |
15388 KB |
Output is correct |
4 |
Correct |
92 ms |
18496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
98 ms |
15976 KB |
Output is correct |
2 |
Correct |
113 ms |
17520 KB |
Output is correct |
3 |
Correct |
69 ms |
16280 KB |
Output is correct |
4 |
Correct |
113 ms |
19820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
821 ms |
35292 KB |
Output is correct |
2 |
Correct |
629 ms |
22796 KB |
Output is correct |
3 |
Correct |
560 ms |
18556 KB |
Output is correct |
4 |
Correct |
1358 ms |
55252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
795 ms |
33976 KB |
Output is correct |
2 |
Correct |
703 ms |
22712 KB |
Output is correct |
3 |
Correct |
457 ms |
17668 KB |
Output is correct |
4 |
Correct |
1618 ms |
59360 KB |
Output is correct |