Submission #1521425
Source Code Expand
#include <bits/stdc++.h> using namespace std; typedef long long lint; typedef pair<int, int> pi; const int MAXN = 100005; int n; lint a[MAXN], b[MAXN]; vector<lint> v; struct bit{ int tree[MAXN]; void add(int x, int v){ while(x <= n){ tree[x] += v; x += x & -x; } } int query(int x){ int ret = 0; while(x){ ret += tree[x]; x -= x & -x; } return ret; } }bit; int main(){ cin >> n; for(int i=1; i<=n; i++){ cin >> a[i]; a[i] += a[i-1]; } for(int i=1; i<n; i++) v.push_back(a[i]); sort(v.begin(), v.end()); vector<lint> w = {v[0]}; for(int i=1; i<v.size(); i++) w.push_back(v[i] - v[i-1]); w.push_back(a[n] - v.back()); for(auto &i : w){ int k; cin >> k; if(k > i){ puts("-1"); return 0; } } for(int i=1; i<n; i++){ a[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin() + 1; } lint cnt = 0; for(int i=1; i<n; i++){ cnt += i - 1 - bit.query(a[i]); bit.add(a[i], 1); } cout << cnt << endl; }
Submission Info
Submission Time | |
---|---|
Task | K - Air Pollution |
User | koosaga |
Language | C++14 (GCC 5.4.1) |
Score | 100 |
Code Size | 1016 Byte |
Status | AC |
Exec Time | 90 ms |
Memory | 3316 KB |
Judge Result
Set Name | All | ||
---|---|---|---|
Score / Max Score | 100 / 100 | ||
Status |
|
Set Name | Test Cases |
---|---|
All | 00_sample1.txt, 00_sample2.txt, 00_sample3.txt, large-random-0.txt, large-random-1.txt, large-random-2.txt, large-random-3.txt, large-random-4.txt, medium-random-0.txt, medium-random-1.txt, medium-random-2.txt, medium-random-3.txt, medium-random-4.txt, medium-random-5.txt, medium-random-6.txt, medium-random-7.txt, medium-random-8.txt, medium-random-9.txt, overflow1.txt, overflow2.txt, small-random-0.txt, small-random-1.txt, small-random-10.txt, small-random-11.txt, small-random-12.txt, small-random-13.txt, small-random-14.txt, small-random-2.txt, small-random-3.txt, small-random-4.txt, small-random-5.txt, small-random-6.txt, small-random-7.txt, small-random-8.txt, small-random-9.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00_sample1.txt | AC | 1 ms | 256 KB |
00_sample2.txt | AC | 1 ms | 256 KB |
00_sample3.txt | AC | 1 ms | 256 KB |
large-random-0.txt | AC | 40 ms | 3316 KB |
large-random-1.txt | AC | 63 ms | 3316 KB |
large-random-2.txt | AC | 63 ms | 3316 KB |
large-random-3.txt | AC | 39 ms | 3188 KB |
large-random-4.txt | AC | 62 ms | 3316 KB |
medium-random-0.txt | AC | 2 ms | 256 KB |
medium-random-1.txt | AC | 2 ms | 256 KB |
medium-random-2.txt | AC | 2 ms | 256 KB |
medium-random-3.txt | AC | 2 ms | 256 KB |
medium-random-4.txt | AC | 2 ms | 256 KB |
medium-random-5.txt | AC | 2 ms | 256 KB |
medium-random-6.txt | AC | 2 ms | 256 KB |
medium-random-7.txt | AC | 2 ms | 256 KB |
medium-random-8.txt | AC | 2 ms | 256 KB |
medium-random-9.txt | AC | 2 ms | 256 KB |
overflow1.txt | AC | 45 ms | 3316 KB |
overflow2.txt | AC | 90 ms | 3316 KB |
small-random-0.txt | AC | 2 ms | 256 KB |
small-random-1.txt | AC | 2 ms | 256 KB |
small-random-10.txt | AC | 1 ms | 256 KB |
small-random-11.txt | AC | 1 ms | 256 KB |
small-random-12.txt | AC | 1 ms | 256 KB |
small-random-13.txt | AC | 1 ms | 256 KB |
small-random-14.txt | AC | 1 ms | 256 KB |
small-random-2.txt | AC | 2 ms | 256 KB |
small-random-3.txt | AC | 2 ms | 256 KB |
small-random-4.txt | AC | 2 ms | 256 KB |
small-random-5.txt | AC | 2 ms | 256 KB |
small-random-6.txt | AC | 2 ms | 256 KB |
small-random-7.txt | AC | 2 ms | 256 KB |
small-random-8.txt | AC | 2 ms | 256 KB |
small-random-9.txt | AC | 2 ms | 256 KB |