# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
799159 |
2023-07-31T10:20:45 Z |
dreamoon |
Meteors (POI11_met) |
C++14 |
|
632 ms |
65536 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];
int need[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){
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 <int> typeA, typeB;
for (int i = 0; i < SZ(type); i++){
if (need[type[i]] <= 0) 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 |
Incorrect |
4 ms |
7636 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
7640 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
68 ms |
23492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
79 ms |
18356 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
63 ms |
14596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
99 ms |
16728 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
615 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
632 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |