Submission #288042

#TimeUsernameProblemLanguageResultExecution timeMemory
288042ToMmyDongIdeal city (IOI12_city)C++11
23 / 100
72 ms3572 KiB
#include <iostream> #include <queue> #include <map> #include <algorithm> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<int,int> pii; #define ALL(i) i.begin(), i.end() #define SZ(i) int(i.size()) #define X first #define Y second #ifdef tmd #define debug(...) fprintf(stderr,"#%d-(%s)=",__LINE__,#__VA_ARGS__);_do(__VA_ARGS__); template<typename T> void _do(T &&x){cerr<<x<<endl;} template<typename T, typename ...S> void _do(T &&x, S &&...y) {cerr<<x<<",";_do(y...);} template<typename IT> ostream& __printRng (ostream& os, IT bg, IT ed) { for (IT it=bg;it!=ed;it++) { if (it == bg) os << "{" << *it; else os << "," << *it; } return os << "}"; } template<typename T> ostream& operator << (ostream& os, const vector<T> &vec) { return __printRng(os, ALL(vec)); } template<typename T, typename S> ostream& operator << (ostream& os, const pair<T,S> &pa) { return os << "{" << pa.X << "," << pa.Y << "}"; } #else #define debug(...) #endif const int MAXN = 100083; struct Bit { ll bit[MAXN]; void add (int x, int val) { for (x+=2;x<MAXN;x+=-x&x) { bit[x] += val; } } ll pre (int x) { ll ret = 0; for (x+=2;x>0;x-=-x&x) { ret += bit[x]; } return ret; } ll suf (int x) { return pre(MAXN-3) - pre(x-1); } }bx, by, cx, cy; int DistanceSum(int n, int *x, int *y) { vector<int> vx, vy; for (int i=0; i<n; i++) { vx.emplace_back(x[i]); vy.emplace_back(y[i]); } sort(ALL(vx)); sort(ALL(vy)); vx.resize(unique(ALL(vx))-vx.begin()); vy.resize(unique(ALL(vy))-vy.begin()); ll ans = 0; for (int i=0; i<n; i++) { x[i] = lower_bound(ALL(vx), x[i])-vx.begin(); y[i] = lower_bound(ALL(vy), y[i])-vy.begin(); debug(x[i], y[i]); ans += x[i] * cx.pre(x[i]-1) - bx.pre(x[i]-1); ans += -x[i] * cx.suf(x[i]+1) + bx.suf(x[i]+1); ans += y[i] * cy.pre(y[i]-1) - by.pre(y[i]-1); ans += -y[i] * cy.suf(y[i]+1) + by.suf(y[i]+1); bx.add(x[i], x[i]); by.add(y[i], y[i]); cx.add(x[i], 1); cy.add(y[i], 1); } return ans % 1000000000; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...