This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define str string
#define pb push_back
#define pf push_front
#define nl "\n"
#define ll long long
#define int long long
#define all(v) (v).begin() , (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define ff first
#define ss second
#define len(a) a.size()
#define pii pair<int,int>
const int N = 5e5 + 101;
const int md = 998244353;
const int mod = 1e9 + 7;
const int mega = 1e6 + 3;
const int inf = 1e18;
ll gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(int a, int b) {
return (a / gcd(a, b)) * b;
}
int binpow(int a, int b, int m = mod) {
a %= m;
long long res = 1;
while (b > 0) {
if (b & 1)
res = res * a % m;
a = a * a % m;
b >>= 1;
}
return res;
}
void solve(){
int n , m;
cin >> n >> m;
int a[m + 1];
for(int i = 1; i <= m; ++i)cin >> a[i];
int p[n + 1];
for(int i = 1; i <= n; ++i)cin >> p[i];
int k;
cin >> k;
vector<int>mp(n + 1 , 0) , ans(n + 1 , 0);
for(int j = 1; j <= k; ++j){
int l , r;
cin >> l >> r;
int x;
cin >> x;
if(l <= r){
for(int i = l; i <= r; i++){
mp[a[i]] += x;
if(mp[a[i]] >= p[a[i]] && ans[a[i]] == 0)ans[a[i]] = j;
}
}
else{
for(int i = l; i <= m; ++i){
mp[a[i]] += x;
if(mp[a[i]] >= p[a[i]] && ans[a[i]] == 0)ans[a[i]] = j;
}
// for(int i = 1; i <= n; ++i){
// if(mp[i] >= p[i])ans[i] = j;
// }
for(int i = 1; i <= r; ++i){
mp[a[i]] += x;
if(mp[a[i]] >= p[a[i]] && ans[a[i]] == 0)ans[a[i]] = j;
}
// for(int i = 1; i <= n; ++i){
// if(mp[i] >= p[i])ans[i] = j;
// }
}
}
for(int i = 1; i <= n; ++i){
if(mp[i] < p[i])cout << "NIE";
else {
// cout << mp[i] << nl;
cout << ans[i];
}
cout << nl;
}
}
signed main() {
// SPEED;
int t = 1;
// cin >> t;
while (t--) {
solve();
}
#ifndef ONLINE_JUDGE
cerr << "\n" << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |