Submission #1088595

#TimeUsernameProblemLanguageResultExecution timeMemory
1088595SunbaeDetecting Molecules (IOI16_molecules)C++17
69 / 100
53 ms10476 KiB
#include "molecules.h" #include <bits/stdc++.h> typedef long long ll; #define mp make_pair #define F first #define S second using namespace std; using pii = pair<int,int>; const int N = 2e5 + 5; pii A[N]; int m, bit[N*3]; ll qs[N], cp[N]; int pos(ll x){ return upper_bound(cp, cp+m, x) - cp;} int qry(int i){ int res = 0; for(; i; i-=i&-i) res += bit[i]; return res;} void upd(int i, int v){ for(; i<=m; i+=i&-i) bit[i] += v;} vector<int> find_subset(int L, int R, vector<int> w){ int n = w.size(); for(int i = 0; i<n; ++i) A[i] = mp(w[i], i); sort(A, A+n); for(int i = 0; i<n; ++i) qs[i] = A[i].F; for(int i = 1; i<n; ++i) qs[i] += qs[i-1]; m = 0; cp[m++] = 0; for(int i = 0; i<n; ++i){ cp[m++] = qs[i]; cp[m++] = qs[i] - L; cp[m++] = qs[i] - R;} sort(cp, cp+m); m = unique(cp, cp+m) - cp; memset(bit, 0, sizeof(bit)); upd(pos(0), +1); vector<int> I; for(int i = 0; i<n; ++i){ if(qry(pos(qs[i] - L)) > qry(pos(qs[i] - R) - 1)){ if(qs[i]-R <= 0 && 0 <= qs[i]-L){ m = 0; I.resize(i+1); for(int j = 0; j<=i; ++j) I[m++] = A[j].S; return I; } for(int j = 0; j<i; ++j){ if(qs[i]-R <= qs[j] && qs[j] <= qs[i]-L){ m = 0; I.resize(i-j); for(int k = j+1; k<=i; ++k) I[m++] = A[k].S; return I; } } } upd(pos(qs[i]), +1); } return vector<int>(); }
#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...