# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
869625 |
2023-11-05T04:31:54 Z |
abhidot |
Meteors (POI11_met) |
C++17 |
|
680 ms |
41260 KB |
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define ll long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mod 1000000007
#define mod2 998244353
#define lld long double
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define V vector
#define setbits(x) __builtin_popcountll(x)
#define w(x) int x; cin>>x; while(x--)
using namespace std;
using namespace __gnu_pbds;
template <typename num_t> using ordered_set = tree<num_t, null_type, less<num_t>, rb_tree_tag, tree_order_statistics_node_update>;
const long long N=300005, INF=2000000000000000000, inf = 2e9+5;
int power(int a, int b, int p){
if(a==0)
return 0;
int res=1;
a%=p;
while(b>0)
{
if(b&1)
res=(res*a)%p;
b>>=1;
a=(a*a)%p;
}
return res;
}
void print(bool n){
if(n){
cout<<"YES\n";
}else{
cout<<"NO\n";
}
}
int n, m, q, till=0;
vector<int> owners, reqd, ans;
vector<vector<int>> queries, inc;
struct FenwickTree {
vector<int> bit; // binary indexed tree
int n;
FenwickTree(int n) {
this->n = n;
bit.assign(n, 0);
}
FenwickTree(vector<int> a) : FenwickTree(a.size()) {
for (size_t i = 0; i < a.size(); i++)
update(i, a[i]);
}
int sum(int r) {
int ret = 0;
for (; r >= 0; r = (r & (r + 1)) - 1)
ret += bit[r];
return ret;
}
int sum(int l, int r) {
return sum(r) - sum(l - 1);
}
void update(int idx, int delta) {
for (; idx < n; idx = idx | (idx + 1))
bit[idx] += delta;
}
void update(int delta, int l, int r){
update(l, delta);
update(r+1, -delta);
}
};
FenwickTree bit(0);
void apply(int l, int r, int a){
if(l<=r){
bit.update(a, l, r);
}else{
bit.update(a, 1, r);
bit.update(a, l, m);
}
}
void update(int idx){
while(till<idx){
till++;
apply(queries[till][0], queries[till][1], queries[till][2]);
}
while(till>idx){
apply(queries[till][0], queries[till][1], -queries[till][2]);
till--;
}
}
void rec(int l, int r, vector<int>& states){
if(l==r){
for(int i:states) ans[i]=l;
states.clear();
return;
}
int mid = (l+r)/2;
update(mid);
int sm=0;
vector<int> L, R;
for(int i:states){
int have=0;
for(int j:inc[i]){
have+=bit.sum(j);
}
if(have>=reqd[i]) L.pb(i), ans[i]=mid;
else R.pb(i), ans[i]=mid+1;
}
states.clear();
rec(l, mid, L);
rec(mid+1, r, R);
}
int32_t main()
{
IOS;
cin>>n>>m;
owners.resize(m+1);
reqd.resize(n);
ans.resize(n, -1);
inc.resize(n);
bit.n=m+2;
bit.bit.assign(m+2, 0);
for(int i=1;i<=m;i++){
cin>>owners[i];
owners[i]--;
inc[owners[i]].pb(i);
}
for(int i=0;i<n;i++){
cin>>reqd[i];
}
cin>>q;
queries.resize(q+2);
queries[0]={0,0,0};
queries[q+1]={0,0,0};
for(int i=1;i<=q;i++){
int l, r, a;
cin>>l>>r>>a;
queries[i]={l, r, a};
}
vector<int> states;
for(int i=0;i<n;i++) states.pb(i);
rec(0, q+1, states);
for(int i=0;i<n;i++){
if(ans[i]==q+1){
cout<<"NIE\n";
}else cout<<ans[i]<<"\n";
}
}
Compilation message
met.cpp: In function 'void rec(long long int, long long int, std::vector<long long int>&)':
met.cpp:123:6: warning: unused variable 'sm' [-Wunused-variable]
123 | int sm=0;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
5444 KB |
Output is correct |
2 |
Correct |
69 ms |
8916 KB |
Output is correct |
3 |
Correct |
55 ms |
5704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
5208 KB |
Output is correct |
2 |
Correct |
60 ms |
5208 KB |
Output is correct |
3 |
Correct |
71 ms |
7756 KB |
Output is correct |
4 |
Correct |
19 ms |
3852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
5028 KB |
Output is correct |
2 |
Correct |
50 ms |
8076 KB |
Output is correct |
3 |
Correct |
23 ms |
3164 KB |
Output is correct |
4 |
Correct |
54 ms |
5944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
4312 KB |
Output is correct |
2 |
Correct |
61 ms |
5524 KB |
Output is correct |
3 |
Correct |
37 ms |
4700 KB |
Output is correct |
4 |
Correct |
63 ms |
7080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
680 ms |
41260 KB |
Output is correct |
2 |
Incorrect |
446 ms |
23904 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
610 ms |
36964 KB |
Output is correct |
2 |
Incorrect |
540 ms |
24128 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |