# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
799343 |
2023-07-31T12:58:49 Z |
dreamoon |
Meteors (POI11_met) |
C++14 |
|
1176 ms |
44228 KB |
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
#define SZ(X) (int)(X.size())
#define MAX 300005
#define pii pair <int,ll>
#define ind first
#define val second
#define INF (ll)(1e18)
using namespace std;
struct Query{
int le, ri, amo;
};
int typeNum, len, queNum;
int arr[MAX];
int ans[MAX];
ll need[MAX],pre[MAX];
vector <int> sta[MAX]; // stations of every type
vector <Query> allQ;
vector <int> allT;
int a, b, c;
void solve(int le, int ri, vector <int> & type){ // type: station types and how much is needed, pos = le
//cout << le << " " << ri << " " << SZ(type) << "\n";
if (type.empty()) return;
vector <pii> loc; // considered locations and dif
vector <int> tCopy; // copy of type
for (int t : type){
pre[t] = need[t];
for (int s : sta[t])
loc.push_back({s, 0});
tCopy.push_back(t);
}
sort(loc.begin(), loc.end());
if (loc.empty()) return;
int mid = le + (ri-le+2)/2;
for (int i = le; i < mid; i++){ // set up prefix difference
Query q = allQ[i];
int add = q.le, sub = q.ri;
if (q.le > q.ri) { // ring-shaped array
loc[0].val += q.amo;
}
auto it = lower_bound(loc.begin(), loc.end(), make_pair(add, -INF));
if (it != loc.end()) it->val += q.amo;
it = lower_bound(loc.begin(), loc.end(), make_pair(sub+1, -INF));
if (it != loc.end()) it->val -= q.amo;
}
ll sum = 0;
for (pii l : loc){ // use prefix difference to calculate how much more we need for each type
sum += l.val;
auto it = lower_bound(tCopy.begin(), tCopy.end(), arr[l.ind]);
need[*it] -= sum;
//cout << sum << " ";
}
if (le == ri){ // this is the final step
for (int t : tCopy){
if (need[t] <= 0) ans[t] = le+1;
}
return;
}
{
vector <pii> tmp;
loc.swap(tmp);
vector <int> tmp2;
tCopy.swap(tmp2);
}
vector <int> typeA, typeB;
for (int i = 0; i < SZ(type); i++){
if (need[type[i]] <= 0) {
need[type[i]] = pre[type[i]];
typeA.push_back(type[i]);
}
else typeB.push_back(type[i]);
}
solve(le, mid-1, typeA);
solve(mid, ri, typeB);
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> typeNum >> len;
for (int i = 1; i <= len; i++) {
cin >> arr[i];
sta[arr[i]].push_back(i);
}
for (int i = 1; i <= typeNum; i++){
cin >> need[i];
allT.push_back(i);
}
cin >> queNum;
for (int i = 0; i < queNum; i++){
cin >> a >> b >> c;
allQ.push_back({a, b, c});
}
solve(0, queNum-1, allT);
for (int i = 1; i <= typeNum; i++){
if (ans[i] == 0) cout << "NIE\n";
else cout << ans[i] << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7380 KB |
Output is correct |
2 |
Correct |
5 ms |
7388 KB |
Output is correct |
3 |
Correct |
5 ms |
7380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7380 KB |
Output is correct |
2 |
Correct |
5 ms |
7380 KB |
Output is correct |
3 |
Correct |
5 ms |
7516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
10512 KB |
Output is correct |
2 |
Correct |
163 ms |
13392 KB |
Output is correct |
3 |
Correct |
132 ms |
10640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
94 ms |
10356 KB |
Output is correct |
2 |
Correct |
112 ms |
10572 KB |
Output is correct |
3 |
Correct |
147 ms |
12552 KB |
Output is correct |
4 |
Correct |
47 ms |
10516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
10388 KB |
Output is correct |
2 |
Correct |
75 ms |
11924 KB |
Output is correct |
3 |
Correct |
21 ms |
8520 KB |
Output is correct |
4 |
Correct |
102 ms |
10744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
77 ms |
10352 KB |
Output is correct |
2 |
Correct |
107 ms |
10844 KB |
Output is correct |
3 |
Correct |
61 ms |
10520 KB |
Output is correct |
4 |
Correct |
115 ms |
11168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1176 ms |
44228 KB |
Output is correct |
2 |
Incorrect |
276 ms |
33340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1104 ms |
41844 KB |
Output is correct |
2 |
Incorrect |
260 ms |
31840 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |