# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
112222 | 2019-05-17T21:28:35 Z | JustasZ | Detecting Molecules (IOI16_molecules) | C++14 | 0 ms | 0 KB |
#include "molecules.h" #include <bits/stdc++.h> #define pb push_back #define all(a) a.begin(), a.end() #define sz(a) (int)a.size() #define x first #define y second #define debug(...) cout << "[" << #__VA_ARGS__ << ": " << __VA_ARGS__ << "]\n" #define rd() abs((int)rng()) using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int>pii; const int maxn = 1e5 + 100; const int mod = 1e9 + 7; mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); vector<int>solve(int l, int r, vector<int>a) { vector<pii>v; for(int i = 0; i < sz(a); i++) v.pb({a[i], i + 1}); sort(all(v)); vector<int>pref(sz(v), 0), suf(sz(v), 0); pref[0] = v[0].x; suf[sz(v) - 1] = v.back().x; for(int i = 1; i < sz(v); i++) pref[i] = pref[i - 1] + v[i].x; for(int i = sz(v) - 2; i >= 0; i--) suf[i] = suf[i + 1] + v[i].x; for(int siz = 1; siz <= sz(v); siz++) { if(pref[siz - 1] <= r && suf[sz(v) - siz] >= l) { ll sum = 0; for(int i = 0; i < sz(v); i++) { sum += v[i].x; if(i >= siz) sum -= v[i - siz].x; if(i >= siz - 1 && sum >= l && sum <= r) { vector<int>ans; for(int j = i - siz + 1; j <= i; j++) ans.pb(v[j].y); return ans; } } } } return {}; }