Submission #1015600

# Submission time Handle Problem Language Result Execution time Memory
1015600 2024-07-06T14:58:08 Z Rifal Meteors (POI11_met) C++14
100 / 100
1177 ms 65536 KB
#include <bits/stdc++.h>
#include <fstream>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define pb push_back
#define mod 1000000007
#define INF 100000000000000000
#define INF2 2000000000
#define fi first
#define se second
using namespace std;
double const EPS = 1e-14;
const int P = 1007;
typedef long long ll;
using namespace __gnu_pbds;
typedef long long ll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // find_by_order, order_of_key
const int N = 3e5 + 4;
ll arr[N], tar[N];
int ans[N];
vector<int> mid[N], where[N];
pair<int,int> rang[N];
struct Q 
{
    int l, r; ll val;
};
Q query[N];
int main()
{
    ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
    int n, m; cin >> n >> m;
    for(int i = 1; i <= m; i++){
         cin >> arr[i];
         where[arr[i]].push_back(i);
    }
    for(int i = 1; i <= n; i++) {
        cin >> tar[i];
        ans[i] = -1;
    }
    int k; cin >> k;
    for(int i = 1; i <= k; i++) {
        int a, b; ll c;
        cin >> a >> b >> c;
        query[i].l = a;
        query[i].r = b;
        query[i].val = c;
    }
    for(int i = 1; i <= n; i++) {
        rang[i].fi = 1;
        rang[i].se = k;
    }
    while(true) {
        ll cal[m+2] = {};
        bool ok = false;
        for(int i = 1; i <= n; i++) {
            if(rang[i].fi <= rang[i].se) {
                ll indx = (rang[i].fi+rang[i].se)/2;
                mid[indx].push_back(i);
                ok = true;
            }
        }
        if(!ok) break;
        for(int i = 1; i <= k; i++) {
            int l = query[i].l, r = query[i].r;
            ll val = query[i].val;
            if(l <= r) {
                for(int j = l; j <= m; j += -j&j) cal[j] += val;
                for(int j = r+1; j <= m; j += -j&j) cal[j] -= val;
            }
            else {
                for(int j = 1; j <= m; j += -j&j) cal[j] += val;
                for(int j = r+1; j <= m; j += -j&j) cal[j] -= val;
                for(int j = l; j <= m; j += -j&j) cal[j] += val;
            }
            if(mid[i].size() > 0) {
                for(auto j : mid[i]) {
                    ll sum = 0;
                    for(auto z : where[j]) {
                        for(int indx = z; indx > 0; indx -= -indx&indx) {
                            sum += cal[indx];
                        }
                        if(sum >= tar[j]) break;
                    }
                    if(sum >= tar[j]) {
                        rang[j].se = i-1;
                        ans[j] = i;
                    }
                    else {
                        rang[j].fi = i+1;
                    }
                }
                mid[i].clear();
            }
        }
    }
    for(int i = 1; i <= n; i++) {
        if(ans[i] != -1) cout << ans[i] << endl;
        else cout << "NIE" << endl;
    }
    return 0;
}
 
# Verdict Execution time Memory Grader output
1 Correct 3 ms 20824 KB Output is correct
2 Correct 3 ms 20828 KB Output is correct
3 Correct 3 ms 20932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 20824 KB Output is correct
2 Correct 3 ms 20920 KB Output is correct
3 Correct 4 ms 21080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 26264 KB Output is correct
2 Correct 86 ms 26180 KB Output is correct
3 Correct 64 ms 27728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 27220 KB Output is correct
2 Correct 65 ms 27212 KB Output is correct
3 Correct 87 ms 28184 KB Output is correct
4 Correct 19 ms 24924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 26708 KB Output is correct
2 Correct 63 ms 28756 KB Output is correct
3 Correct 32 ms 23132 KB Output is correct
4 Correct 67 ms 28028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 23900 KB Output is correct
2 Correct 77 ms 27240 KB Output is correct
3 Correct 47 ms 24156 KB Output is correct
4 Correct 85 ms 29320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 874 ms 41124 KB Output is correct
2 Correct 566 ms 29484 KB Output is correct
3 Correct 151 ms 25424 KB Output is correct
4 Correct 1046 ms 63424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 830 ms 40904 KB Output is correct
2 Correct 598 ms 30928 KB Output is correct
3 Correct 130 ms 25268 KB Output is correct
4 Correct 1177 ms 65536 KB Output is correct