# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
789076 |
2023-07-21T01:56:09 Z |
Dawnlight |
Meteors (POI11_met) |
C++17 |
|
467 ms |
65536 KB |
#include <bits/stdc++.h>
#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];
vector <int> sta[MAX]; // stations of every type
vector <Query> allQ;
vector <pii> allT;
int a, b, c;
void solve(vector <Query> & queA, vector <pii> & type, int pos){ // type: station types and how much is needed, pos = le
//cout << SZ(queA) << " " << SZ(type) << " " << pos << "\n";
if (type.empty() || queA.empty()) return;
vector <pii> loc; // considered locations and dif
vector <pii> tCopy; // copy of type
for (pii t : type){
for (int s : sta[t.ind])
loc.push_back({s, 0});
tCopy.push_back(t);
}
sort(loc.begin(), loc.end());
if (loc.empty()) return;
vector <Query> queB; // separate que into first and second half
int sz = SZ(queA);
for (int i = 0; i < sz/2; i++){
queB.push_back(queA.back());
queA.pop_back();
}
reverse(queB.begin(), queB.end());
//cout << SZ(queA) << " " << SZ(queB) << "\n";
for (Query q : queA){ // set up prefix difference
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(), make_pair(arr[l.ind], -INF));
it->val -= sum;
//cout << sum << " ";
}
if (queA.empty() || queB.empty()){ // this is the final step
for (pii t : tCopy){
if (t.val <= 0) ans[t.ind] = pos;
}
return;
}
vector <pii> typeA, typeB;
for (int i = 0; i < SZ(type); i++){
if (tCopy[i].val <= 0) typeA.push_back(type[i]);
else typeB.push_back(tCopy[i]);
}
sz = SZ(queA);
solve(queA, typeA, pos);
solve(queB, typeB, pos+sz);
}
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 >> a;
allT.push_back({i, a});
}
cin >> queNum;
for (int i = 1; i <= queNum; i++){
cin >> a >> b >> c;
allQ.push_back({a, b, c});
}
solve(allQ, allT, 1);
for (int i = 1; i <= typeNum; i++){
if (ans[i] == 0) cout << "NIE\n";
else cout << ans[i] << "\n";
}
return 0;
}
/*
10 11
1 2 3 4 5 6 7 8 9 10 11
1 2 3 4 5 6 7 8 9 10
10
1 3 1
3 4 1
7 1 1
1 5 1
1 5 1
6 6 1
7 7 1
8 8 1
9 9 1
10 10 1
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7512 KB |
Output is correct |
2 |
Correct |
6 ms |
7764 KB |
Output is correct |
3 |
Correct |
5 ms |
7508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7764 KB |
Output is correct |
2 |
Correct |
5 ms |
7764 KB |
Output is correct |
3 |
Correct |
5 ms |
7764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
20280 KB |
Output is correct |
2 |
Correct |
175 ms |
38280 KB |
Output is correct |
3 |
Correct |
145 ms |
14552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
94 ms |
13992 KB |
Output is correct |
2 |
Correct |
112 ms |
14068 KB |
Output is correct |
3 |
Correct |
160 ms |
28612 KB |
Output is correct |
4 |
Correct |
54 ms |
20816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
16092 KB |
Output is correct |
2 |
Correct |
88 ms |
29480 KB |
Output is correct |
3 |
Correct |
22 ms |
9376 KB |
Output is correct |
4 |
Correct |
111 ms |
16192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
82 ms |
19240 KB |
Output is correct |
2 |
Correct |
125 ms |
20448 KB |
Output is correct |
3 |
Correct |
64 ms |
14040 KB |
Output is correct |
4 |
Correct |
125 ms |
20892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
462 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
467 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |