제출 #495008

#제출 시각아이디문제언어결과실행 시간메모리
495008gozoniteSails (IOI07_sails)C++14
90 / 100
1087 ms3672 KiB
#include <iostream> #include <vector> #include <string> #include <fstream> #include <algorithm> #include <climits> #include <cstdlib> #include <cstdio> #include <set> #include <unordered_set> #include <map> #include <unordered_map> #include <bitset> #include <deque> #include <queue> #include <tuple> #include <cmath> #include <cctype> #include <stack> #include <cassert> using namespace std; using ll = long long; int N; pair<int, int> inp[100001]; int bit[100002]={}; set<int> pos; // where all the jumps in flags are located void add(int k, int x) { while (k <= 1e5) { bit[k] += x; k += k&-k; } } void inc(int a, int b, int amt) { add(a, amt); add(b+1, -amt); } int sum(int k) { int s = 0; while (k >= 1) { s += bit[k]; k -= k&-k; } return s; } int get(int k) { return sum(k); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> N; pos.insert(1); for (int i = 1; i <= N; i++) cin >> inp[i].first >> inp[i].second; sort(inp+1, inp+1+N); // idx = 1 inc(1, inp[1].second, 1); pos.insert(inp[1].second+1); //cout << "pos, bit" << endl; //for (auto pp : pos) cout << pp << " "; cout << endl; //for (int i = 1; i <= 20; i++) cout << get(i) << " "; cout << endl; for (int i = 2; i <= N; i++) { int h = inp[i].first, k = inp[i].second; int b = h-k+1; if (get(h) == 0) pos.insert(h+1); if (h-k+1 > 1) { if (pos.find(b) != pos.end()) { inc(b, h, 1); if (get(b)==get(h-k)) pos.erase(b); } else { auto it = pos.upper_bound(b); int ed = *it; --it; int fp = *it; int size = ed-b; inc(ed, h, 1); inc(fp, fp+size-1, 1); if (get(ed) == get(ed-1)) pos.erase(ed); if (fp != 1 && get(fp) == get(fp-1)) pos.erase(fp); pos.insert(fp+size); // only if new position } } else { inc(b, h, 1); } //cout << "debugging pos,bit" << endl; //for (auto pp : pos) cout << pp << " "; cout << endl; //for (int i = 1; i <= 20; i++) cout << get(i) << " "; cout << endl; } ll ans = 0; for (int i = 1; i <= 1e5; i++) { ll s = get(i); ans += s*(s-1LL)/2LL; } cout << ans << endl; return 0; } /* 11 3 2 5 3 4 1 2 1 4 3 3 2 6 6 6 6 7 1 7 2 8 2 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...