Submission #496332

#TimeUsernameProblemLanguageResultExecution timeMemory
496332NalrimetMeteors (POI11_met)C++17
0 / 100
6096 ms16248 KiB
#include<bits/stdc++.h>
using namespace std;

const int N = 3 * 1e5 + 5;
const long long inf = 1000000000;
#define ll long long

#define F first
#define S second
#define pb push_back

int n, m, a[N], k, l, r, ans[N], j;
ll b[N], x;
set<int> st;
vector<int> del;

 main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> m;

    for(int i = 1; i <= m; ++i){
        cin >> a[i];
        st.insert(i);
    }

    for(int i = 1; i <= n; ++i){
        cin >> b[i];
    }

    cin >> k;

    for(int i = 1; i <= k; ++i){
        cin >> l >> r >> x;
        if(l <= r){
            auto to = st.lower_bound(l);
            if(to == st.end()) continue;
            for(to; *to <= r;){
                j = *to;
                if(b[a[j]] <= 0) del.pb(j);
                else{
                    b[a[j]] -= x;
                    if(b[a[j]] <= 0) {ans[a[j]] = i; del.pb(j);}
                }
                to++;
                if(to == st.end()) break;
            }
        }
        else{
            auto to = st.lower_bound(l);
            if(to == st.end()) continue;
            for(to; *to <= m; ){
                j = *to;
                if(b[a[j]] <= 0) del.pb(j);
                else{
                    b[a[j]] -= x;
                    if(b[a[j]] <= 0) {ans[a[j]] = i; del.pb(j);}
                }
                to++;
                if(to == st.end()) break;
            }
            to = st.begin();
            if(to == st.end()) continue;
            for(to; *to <= r; ){
                j = *to;
                if(b[a[j]] <= 0) del.pb(j);
                else{
                    b[a[j]] -= x;
                    if(b[a[j]] <= 0) {ans[a[j]] = i; del.pb(j);}
                }
                to++;
                if(to == st.end()) break;
            }
        }
        for(auto to : del){
            st.erase(to);
        }
        del.clear();
    }

    for(int i = 1; i <= n; ++i){
        if(ans[i]) cout << ans[i] << '\n';
        else cout << "NIE\n";
    }
}

Compilation message (stderr)

met.cpp:17:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   17 |  main() {
      |  ^~~~
met.cpp: In function 'int main()':
met.cpp:41:17: warning: statement has no effect [-Wunused-value]
   41 |             for(to; *to <= r;){
      |                 ^~
met.cpp:55:17: warning: statement has no effect [-Wunused-value]
   55 |             for(to; *to <= m; ){
      |                 ^~
met.cpp:67:17: warning: statement has no effect [-Wunused-value]
   67 |             for(to; *to <= r; ){
      |                 ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...