fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. using ll = long long;
  5. using db = long double; // or double, if TL is tight
  6. using str = string; // yay python!
  7.  
  8. using pi = pair<int,int>;
  9. using pl = pair<ll,ll>;
  10. using pd = pair<db,db>;
  11.  
  12. using vi = vector<int>;
  13. using vb = vector<bool>;
  14. using vl = vector<ll>;
  15. using vd = vector<db>;
  16. using vs = vector<str>;
  17. using vpi = vector<pi>;
  18. using vpl = vector<pl>;
  19. using vpd = vector<pd>;
  20.  
  21. #define tcT template<class T
  22. #define tcTU tcT, class U
  23. // ^ lol this makes everything look weird but I'll try it
  24. tcT> using V = vector<T>;
  25. tcT, size_t SZ> using AR = array<T,SZ>;
  26. tcT> using PR = pair<T,T>;
  27.  
  28. // pairs
  29. #define mp make_pair
  30. #define f first
  31. #define s second
  32.  
  33. // vectors
  34. // oops size(x), rbegin(x), rend(x) need C++17
  35. #define sz(x) int((x).size())
  36. #define bg(x) begin(x)
  37. #define all(x) bg(x), end(x)
  38. #define rall(x) x.rbegin(), x.rend()
  39. #define sor(x) sort(all(x))
  40. #define rsz resize
  41. #define ins insert
  42. #define ft front()
  43. #define bk back()
  44. #define pb push_back
  45. #define eb emplace_back
  46. #define pf push_front
  47. #define rtn return
  48.  
  49. #define lb lower_bound
  50. #define ub upper_bound
  51. tcT> int lwb(V<T>& a, const T& b) { return int(lb(all(a),b)-bg(a)); }
  52.  
  53. // loops
  54. #define FOR(i,a,b) for (int i = (a); i < (b); ++i)
  55. #define F0R(i,a) FOR(i,0,a)
  56. #define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
  57. #define R0F(i,a) ROF(i,0,a)
  58. #define rep(a) F0R(_,a)
  59. #define each(a,x) for (auto& a: x)
  60.  
  61. const int MOD = 1e9+7; // 998244353;
  62. const int MX = 2e5+5;
  63. const ll INF = 1e18; // not too close to LLONG_MAX
  64. const db PI = acos((db)-1);
  65. const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1}; // for every grid problem!!
  66. mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
  67. template<class T> using pqg = priority_queue<T,vector<T>,greater<T>>;
  68.  
  69. // bitwise ops
  70. // also see https://g...content-available-to-author-only...u.org/onlinedocs/gcc/Other-Builtins.html
  71. constexpr int pct(int x) { return __builtin_popcount(x); } // # of bits set
  72. constexpr int bits(int x) { // assert(x >= 0); // make C++11 compatible until USACO updates ...
  73. return x == 0 ? 0 : 31-__builtin_clz(x); } // floor(log2(x))
  74. constexpr int p2(int x) { return 1<<x; }
  75. constexpr int msk2(int x) { return p2(x)-1; }
  76.  
  77. ll cdiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up
  78. ll fdiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down
  79.  
  80. tcT> bool ckmin(T& a, const T& b) {
  81. return b < a ? a = b, 1 : 0; } // set a = min(a,b)
  82. tcT> bool ckmax(T& a, const T& b) {
  83. return a < b ? a = b, 1 : 0; }
  84.  
  85. tcTU> T fstTrue(T lo, T hi, U f) {
  86. hi ++; assert(lo <= hi); // assuming f is increasing
  87. while (lo < hi) { // find first index such that f is true
  88. T mid = lo+(hi-lo)/2;
  89. f(mid) ? hi = mid : lo = mid+1;
  90. }
  91. return lo;
  92. }
  93. tcTU> T lstTrue(T lo, T hi, U f) {
  94. lo --; assert(lo <= hi); // assuming f is decreasing
  95. while (lo < hi) { // find first index such that f is true
  96. T mid = lo+(hi-lo+1)/2;
  97. f(mid) ? lo = mid : hi = mid-1;
  98. }
  99. return lo;
  100. }
  101. tcT> void remDup(vector<T>& v) { // sort and remove duplicates
  102. sort(all(v)); v.erase(unique(all(v)),end(v)); }
  103. tcTU> void erase(T& t, const U& u) { // don't erase
  104. auto it = t.find(u); assert(it != end(t));
  105. t.erase(it); } // element that doesn't exist from (multi)set
  106.  
  107. #define tcTUU tcT, class ...U
  108.  
  109. inline namespace Helpers {
  110. //////////// is_iterable
  111. // https://stackoverflow.com/questions/13830158/check-if-a-variable-type-is-iterable
  112. // this gets used only when we can call begin() and end() on that type
  113. tcT, class = void> struct is_iterable : false_type {};
  114. tcT> struct is_iterable<T, void_t<decltype(begin(declval<T>())),
  115. decltype(end(declval<T>()))
  116. >
  117. > : true_type {};
  118. tcT> constexpr bool is_iterable_v = is_iterable<T>::value;
  119.  
  120. //////////// is_readable
  121. tcT, class = void> struct is_readable : false_type {};
  122. tcT> struct is_readable<T,
  123. typename std::enable_if_t<
  124. is_same_v<decltype(cin >> declval<T&>()), istream&>
  125. >
  126. > : true_type {};
  127. tcT> constexpr bool is_readable_v = is_readable<T>::value;
  128.  
  129. //////////// is_printable
  130. // // https://n...content-available-to-author-only...e.es/posts/2020-02-29-is-printable/
  131. tcT, class = void> struct is_printable : false_type {};
  132. tcT> struct is_printable<T,
  133. typename std::enable_if_t<
  134. is_same_v<decltype(cout << declval<T>()), ostream&>
  135. >
  136. > : true_type {};
  137. tcT> constexpr bool is_printable_v = is_printable<T>::value;
  138. }
  139.  
  140. inline namespace Input {
  141. tcT> constexpr bool needs_input_v = !is_readable_v<T> && is_iterable_v<T>;
  142. tcTUU> void re(T& t, U&... u);
  143. tcTU> void re(pair<T,U>& p); // pairs
  144.  
  145. // re: read
  146. tcT> typename enable_if<is_readable_v<T>,void>::type re(T& x) { cin >> x; } // default
  147. tcT> void re(complex<T>& c) { T a,b; re(a,b); c = {a,b}; } // complex
  148. tcT> typename enable_if<needs_input_v<T>,void>::type re(T& i); // ex. vectors, arrays
  149. tcTU> void re(pair<T,U>& p) { re(p.f,p.s); }
  150. tcT> typename enable_if<needs_input_v<T>,void>::type re(T& i) {
  151. each(x,i) re(x); }
  152. tcTUU> void re(T& t, U&... u) { re(t); re(u...); } // read multiple
  153.  
  154. // rv: resize and read vectors
  155. void rv(size_t) {}
  156. tcTUU> void rv(size_t N, V<T>& t, U&... u);
  157. template<class...U> void rv(size_t, size_t N2, U&... u);
  158. tcTUU> void rv(size_t N, V<T>& t, U&... u) {
  159. t.rsz(N); re(t);
  160. rv(N,u...); }
  161. template<class...U> void rv(size_t, size_t N2, U&... u) {
  162. rv(N2,u...); }
  163.  
  164. // dumb shortcuts to read in ints
  165. void decrement() {} // subtract one from each
  166. tcTUU> void decrement(T& t, U&... u) { --t; decrement(u...); }
  167. #define ints(...) int __VA_ARGS__; re(__VA_ARGS__);
  168. #define int1(...) ints(__VA_ARGS__); decrement(__VA_ARGS__);
  169. }
  170.  
  171. inline namespace ToString {
  172. tcT> constexpr bool needs_output_v = !is_printable_v<T> && is_iterable_v<T>;
  173.  
  174. // ts: string representation to print
  175. tcT> typename enable_if<is_printable_v<T>,str>::type ts(T v) {
  176. stringstream ss; ss << fixed << setprecision(15) << v;
  177. return ss.str(); } // default
  178. tcT> str bit_vec(T t) { // bit vector to string
  179. str res = "{"; F0R(i,sz(t)) res += ts(t[i]);
  180. res += "}"; return res; }
  181. str ts(V<bool> v) { return bit_vec(v); }
  182. template<size_t SZ> str ts(bitset<SZ> b) { return bit_vec(b); } // bit vector
  183. tcTU> str ts(pair<T,U> p); // pairs
  184. tcT> typename enable_if<needs_output_v<T>,str>::type ts(T v); // vectors, arrays
  185. tcTU> str ts(pair<T,U> p) { return "("+ts(p.f)+", "+ts(p.s)+")"; }
  186. tcT> typename enable_if<is_iterable_v<T>,str>::type ts_sep(T v, str sep) {
  187. // convert container to string w/ separator sep
  188. bool fst = 1; str res = "";
  189. for (const auto& x: v) {
  190. if (!fst) res += sep;
  191. fst = 0; res += ts(x);
  192. }
  193. return res;
  194. }
  195. tcT> typename enable_if<needs_output_v<T>,str>::type ts(T v) {
  196. return "{"+ts_sep(v,", ")+"}"; }
  197.  
  198. // for nested DS
  199. template<int, class T> typename enable_if<!needs_output_v<T>,vs>::type
  200. ts_lev(const T& v) { return {ts(v)}; }
  201. template<int lev, class T> typename enable_if<needs_output_v<T>,vs>::type
  202. ts_lev(const T& v) {
  203. if (lev == 0 || !sz(v)) return {ts(v)};
  204. vs res;
  205. for (const auto& t: v) {
  206. if (sz(res)) res.bk += ",";
  207. vs tmp = ts_lev<lev-1>(t);
  208. res.ins(end(res),all(tmp));
  209. }
  210. F0R(i,sz(res)) {
  211. str bef = " "; if (i == 0) bef = "{";
  212. res[i] = bef+res[i];
  213. }
  214. res.bk += "}";
  215. return res;
  216. }
  217. }
  218.  
  219. inline namespace Output {
  220. template<class T> void pr_sep(ostream& os, str, const T& t) { os << ts(t); }
  221. template<class T, class... U> void pr_sep(ostream& os, str sep, const T& t, const U&... u) {
  222. pr_sep(os,sep,t); os << sep; pr_sep(os,sep,u...); }
  223. // print w/ no spaces
  224. template<class ...T> void pr(const T&... t) { pr_sep(cout,"",t...); }
  225. // print w/ spaces, end with newline
  226. void ps() { cout << "\n"; }
  227. template<class ...T> void ps(const T&... t) { pr_sep(cout," ",t...); ps(); }
  228. // debug to cerr
  229. template<class ...T> void dbg_out(const T&... t) {
  230. pr_sep(cerr," | ",t...); cerr << endl; }
  231. void loc_info(int line, str names) {
  232. cerr << "Line(" << line << ") -> [" << names << "]: "; }
  233. template<int lev, class T> void dbgl_out(const T& t) {
  234. cerr << "\n\n" << ts_sep(ts_lev<lev>(t),"\n") << "\n" << endl; }
  235. #ifdef LOCAL
  236. #define dbg(...) loc_info(__LINE__,#__VA_ARGS__), dbg_out(__VA_ARGS__)
  237. #define dbgl(lev,x) loc_info(__LINE__,#x), dbgl_out<lev>(x)
  238. #else // don't actually submit with this
  239. #define dbg(...) 0
  240. #define dbgl(lev,x) 0
  241. #endif
  242. }
  243.  
  244. inline namespace FileIO {
  245. void setIn(str s) { freopen(s.c_str(),"r",stdin); }
  246. void setOut(str s) { freopen(s.c_str(),"w",stdout); }
  247. void setIO(str s = "") {
  248. cin.tie(0)->sync_with_stdio(0); // unsync C / C++ I/O streams
  249. // cin.exceptions(cin.failbit);
  250. // throws exception when do smth illegal
  251. // ex. try to read letter into int
  252. if (sz(s)) setIn(s+".in"), setOut(s+".out"); // for old USACO
  253. }
  254. }
  255.  
  256. pl& operator+=(pl& a, pl b) { return a = {a.f+b.f,a.s+b.s}; }
  257. pl operator-(pl a, pl b) { return {a.f-b.f,a.s-b.s}; }
  258.  
  259. /**
  260.  * Description: range sum queries and point updates for $D$ dimensions
  261.  * Source: https://c...content-available-to-author-only...s.com/blog/entry/64914
  262.  * Verification: SPOJ matsum
  263.  * Usage: \texttt{BIT<int,10,10>} gives 2D BIT
  264.  * Time: O((\log N)^D)
  265.  */
  266.  
  267. template <class T, int ...Ns> struct BIT {
  268. T val{}; void upd(T v) { val += v; }
  269. T query() { return val; }
  270. };
  271. template <class T, int N, int... Ns> struct BIT<T, N, Ns...> {
  272. BIT<T,Ns...> bit[N+1];
  273. template<typename... Args> void upd(int pos, Args... args) { assert(pos > 0);
  274. for (; pos<=N; pos+=pos&-pos) bit[pos].upd(args...); }
  275. template<typename... Args> T sum(int r, Args... args) {
  276. T res{}; for (;r;r-=r&-r) res += bit[r].query(args...);
  277. return res; }
  278. template<typename... Args> T query(int l, int r, Args...
  279. args) { return sum(r,args...)-sum(l-1,args...); }
  280. };
  281.  
  282. BIT<pl,MX> BB;
  283.  
  284. /**
  285.  * Description: 1D range minimum query. Can also do queries
  286.   * for any associative operation in $O(1)$ with D\&C
  287.  * Source: KACTL
  288.  * Verification:
  289. * https://c...content-available-to-author-only...s.fi/problemset/stats/1647/
  290. * http://w...content-available-to-author-only...g.com/problem/ioi1223
  291. * https://p...content-available-to-author-only...n.com/ChpniVZL
  292.  * Memory: O(N\log N)
  293.  * Time: O(1)
  294.  */
  295.  
  296. template<class T> struct RMQ { // floor(log_2(x))
  297. int level(int x) { return 31-__builtin_clz(x); }
  298. vector<T> v; vector<vi> jmp;
  299. int comb(int a, int b) { // index of min
  300. return v[a]==v[b]?min(a,b):(v[a]>v[b]?a:b); }
  301. void init(const vector<T>& _v) {
  302. v = _v; jmp = {vi(sz(v))}; iota(all(jmp[0]),0);
  303. for (int j = 1; 1<<j <= sz(v); ++j) {
  304. jmp.pb(vi(sz(v)-(1<<j)+1));
  305. F0R(i,sz(jmp[j])) jmp[j][i] = comb(jmp[j-1][i],
  306. jmp[j-1][i+(1<<(j-1))]);
  307. }
  308. }
  309. int index(int l, int r) { // get index of min element
  310. assert(l <= r); int d = level(r-l+1);
  311. return comb(jmp[d][l],jmp[d][r-(1<<d)+1]); }
  312. T query(int l, int r) { return v[index(l,r)]; }
  313. };
  314.  
  315. RMQ<int> R;
  316. struct interval {
  317. int lef, rig, mul;
  318. ll len, contrib;
  319. };
  320.  
  321. V<interval> intervals;
  322.  
  323. int N,M;
  324. int start[MX];
  325. vi A,B;
  326. V<tuple<int,int,int>> queries;
  327. vl ans, cum{0,0};
  328.  
  329. vpi v;
  330.  
  331. int get_x_0(pi p) {
  332. if (p.s == 1) return intervals[p.f].lef;
  333. return get<0>(queries[p.f]);
  334. }
  335.  
  336. pi get_x(pi p) { return mp(get_x_0(p),p.s); }
  337.  
  338.  
  339. int get_y_0(pi p) {
  340. if (p.s == 1) return intervals[p.f].rig;
  341. return get<1>(queries[p.f]);
  342. }
  343.  
  344. pi get_y(pi p) { return mp(get_y_0(p),p.s); }
  345.  
  346.  
  347. ll get_z_0(pi p) {
  348. if (p.s == 1) return intervals[p.f].len;
  349. return get<2>(queries[p.f]);
  350. }
  351.  
  352. pair<ll,int> get_z(pi p) { return mp(get_z_0(p),p.s); }
  353.  
  354. vpl aa;
  355.  
  356. void divi(int l, int r) {
  357. if (l == r) return;
  358. int m = (l+r)/2;
  359. divi(l,m); divi(m+1,r);
  360. vpi tmp;
  361. FOR(i,l,m+1) {
  362. pi a = v[i];
  363. if (a.s == 0) tmp.pb(a);
  364. }
  365. FOR(j,m+1,r+1) {
  366. pi b = v[j];
  367. if (b.s == 1) tmp.pb(b);
  368. }
  369. sort(all(tmp),[](pi a, pi b) {
  370. return get_y(a) < get_y(b);
  371. });
  372. R0F(i,sz(tmp)) {
  373. pi a = tmp[i];
  374. if (a.s == 1) {
  375. int x = get_x_0(a);
  376. if (x > 0) BB.upd(x,pl{intervals[a.f].contrib,intervals[a.f].mul});
  377. } else {
  378. pl p = BB.query(get_x_0(a),N+2);
  379. aa[a.f].f += p.f;
  380. aa[a.f].s += p.s;
  381. }
  382. }
  383. R0F(i,sz(tmp)) {
  384. pi a = tmp[i];
  385. if (a.s == 1) {
  386. int x = get_x_0(a);
  387. if (x > 0) BB.upd(x,pl{-intervals[a.f].contrib,-intervals[a.f].mul});
  388. }
  389. }
  390. // F0R(i,sz(tmp)) FOR(j,i+1,sz(tmp)) {
  391. // pi a = tmp[i], b = tmp[j];
  392. // if (a.s == 0 && b.s == 1 && get_x(a) < get_x(b)) {
  393. // aa[a.f].f += intervals[b.f].contrib;
  394. // aa[a.f].s += intervals[b.f].mul;
  395. // }
  396. // }
  397. // for (pi a: a_tmp) for (pi b: b_tmp) {
  398. // if (get_x(a) < get_x(b))
  399. // if (get_y(a) < get_y(b)) {
  400. // aa[a.f].f += intervals[b.f].contrib;
  401. // aa[a.f].s += intervals[b.f].mul;
  402. // }
  403. // }
  404. }
  405.  
  406. void deal1() {
  407. BB = BIT<pl,MX>();
  408. aa.rsz(M);
  409. each(p,intervals) {
  410. p.contrib = p.mul*p.len;
  411. p.rig *= -1;
  412. -- p.len;
  413. }
  414. each(t,queries) get<1>(t) *= -1;
  415. F0R(i,M) if (ans[i] != -1) {
  416. int S,T,U; tie(S,T,U) = queries[i];
  417. // each(p,intervals) if (S <= p.lef && T <= p.rig && U <= p.len) {
  418. // aa[i].f += p.contrib;
  419. // aa[i].s += p.mul;
  420. // }
  421. }
  422. vpi ii,qq;
  423. F0R(i,sz(intervals)) {
  424. v.pb({i,1});
  425. ii.pb({i,1});
  426. }
  427. F0R(i,sz(queries)) {
  428. v.pb({i,0});
  429. qq.pb({i,0});
  430. }
  431. // for (pi a: qq) for (pi b: ii)
  432. // if (get_x(a) < get_x(b))
  433. // if (get_y(a) < get_y(b))
  434. // if (get_z(a) < get_z(b)) {
  435. // aa[a.f].f += intervals[b.f].contrib;
  436. // aa[a.f].s += intervals[b.f].mul;
  437. // }
  438. // F0R(i,sz(queries)) F0R(j,sz(intervals))
  439. sort(all(v),[&](pi a, pi b) {
  440. return get_z(a) < get_z(b);
  441. });
  442. divi(0,sz(v)-1);
  443.  
  444.  
  445. F0R(i,M) if (ans[i] != -1) {
  446. int S,T,U; tie(S,T,U) = queries[i];
  447. ans[i] += aa[i].f-aa[i].s*U;
  448. }
  449. }
  450.  
  451. void deal2() {
  452. V<AR<ll,5>> contrib;
  453. // dbg("START",ans[0]);
  454. F0R(i,M) if (ans[i] != -1) {
  455. int S,T,U; tie(S,T,U) = queries[i];
  456. int maxLef = lstTrue(0,N+2,[&](int x) {
  457. return cum[x] <= cum[T]-U;
  458. });
  459. int lo = S, hi = min(T-1,maxLef);
  460. if (lo <= hi) {
  461. contrib.pb({hi, T,cum[T]-U,i,1});
  462. contrib.pb({lo-1,T,cum[T]-U,i,-1});
  463. // each(p,intervals) if (p.lef <= hi) {
  464. // if (p.rig > T) ans[i] += p.mul*(-cum[p.lef]+cum[T]-U);
  465. // }
  466. // each(p,intervals) if (p.lef <= lo-1) {
  467. // if (p.rig > T) ans[i] -= p.mul*(-cum[p.lef]+cum[T]-U);
  468. // }
  469. }
  470. }
  471. sor(contrib);
  472. BB = BIT<pl,MX>();
  473. int ind = 0;
  474. each(t,contrib) {
  475. for(;ind < sz(intervals) && intervals[ind].lef <= t[0];++ind) {
  476. const auto& p = intervals[ind];
  477. BB.upd(p.rig,pl{-p.mul*cum[p.lef],p.mul});
  478. }
  479. pl p = BB.query((int)t[1]+1,N+2);
  480. // dbg("AH",p.f+p.s*t[2],t[3],t[4]);
  481. assert(t[3] < sz(ans));
  482. ans[t[3]] += t[4]*(p.f+p.s*t[2]);
  483. }
  484. // dbg("END",ans[0]);
  485. }
  486.  
  487. int main() {
  488. setIO(); re(N,M);
  489. A.rsz(N+1), B.rsz(N+1);
  490. FOR(i,1,N+1) re(A[i]);
  491. FOR(i,1,N+1) re(B[i]);
  492. R.init(A);
  493. FOR(i,1,N+1) cum.pb(cum.bk+A[i]);
  494. cum.pb(cum.bk);
  495. assert(sz(cum)-1 == N+2);
  496. set<int> cur{0,N+2};
  497. vi inds; FOR(i,1,N+2) inds.pb(i);
  498. // F0R(i,N+2) {
  499. // rig[i] = i+1;
  500. // lef[i+1] = i;
  501. // }
  502. sort(all(inds),[&](int x, int y) {
  503. return B[x] < B[y]; });
  504. for (int x: inds) {
  505. cur.ins(x);
  506. auto it = cur.find(x);
  507. int l = *prev(it), r = *next(it);
  508. intervals.pb({l,r,B[x]-start[l],cum[r]-cum[l]});
  509. start[l] = start[x] = B[x];
  510. }
  511. // cout << cum[3]-cum[2] << "\n";
  512. // for (auto a: intervals) cout << "HA " << a.lef << " " << a.rig << " " << a.mul << " " << a.len << "\n";
  513. queries.rsz(M);
  514. ans.rsz(M);
  515. F0R(i,M) {
  516. ints(S,T,U);
  517. queries[i] = {S,T,U};
  518. if (R.query(S,T-1) > U) {
  519. ans[i] = -1;
  520. }
  521. }
  522. sort(all(intervals),[](const interval& a, const interval& b) {
  523. return a.lef < b.lef;
  524. });
  525. deal2();
  526. vi qinds(M); iota(all(qinds),0);
  527. sort(all(qinds),[&](int x, int y) {
  528. return get<0>(queries[x]) < get<0>(queries[y]);
  529. });
  530. int pos = 0;
  531. BB = BIT<pl,MX>();
  532. for (int i: qinds) if (ans[i] != -1) {
  533. int S,T,U; tie(S,T,U) = queries[i];
  534. // each(p,intervals) if (p.lef < S) {
  535. // if (p.rig <= S) {
  536.  
  537. // } else if (p.rig <= T) {
  538. // ans[i] += p.mul*(cum[p.rig]-cum[S]);
  539. // } else {
  540. // ans[i] += p.mul*(cum[T]-cum[S]);
  541. // }
  542.  
  543. // }
  544. for(;pos < sz(intervals) && intervals[pos].lef < S;++pos) {
  545. const auto& p = intervals[pos];
  546. BB.upd(intervals[pos].rig,pl{p.mul*cum[p.rig],p.mul});
  547. }
  548. pl qq = BB.query(S,T);
  549. ans[i] += qq.f-qq.s*cum[S];
  550. qq = BB.query(T+1,N+2);
  551. ans[i] += qq.s*(cum[T]-cum[S]);
  552. }
  553. deal1();
  554. each(t,ans) ps(t);
  555. // you should actually read the stuff at the bottom
  556. }
  557.  
  558. /* stuff you should look for
  559. * int overflow, array bounds
  560. * special cases (n=1?)
  561. * do smth instead of nothing and stay organized
  562. * WRITE STUFF DOWN
  563. * DON'T GET STUCK ON ONE APPROACH
  564. */
  565.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:124:14: error: ‘is_same_v’ was not declared in this scope
              is_same_v<decltype(cin >> declval<T&>()), istream&>
              ^~~~~~~~~
prog.cpp:124:14: note: suggested alternative: ‘iswspace_l’
              is_same_v<decltype(cin >> declval<T&>()), istream&>
              ^~~~~~~~~
              iswspace_l
prog.cpp:124:64: error: template argument 1 is invalid
              is_same_v<decltype(cin >> declval<T&>()), istream&>
                                                                ^
prog.cpp:125:10: error: template argument 2 is invalid
          >
          ^
prog.cpp:126:6: error: expected unqualified-id before ‘>’ token
      > : true_type {};
      ^
prog.cpp:134:14: error: ‘is_same_v’ was not declared in this scope
              is_same_v<decltype(cout << declval<T>()), ostream&>
              ^~~~~~~~~
prog.cpp:134:14: note: suggested alternative: ‘iswspace_l’
              is_same_v<decltype(cout << declval<T>()), ostream&>
              ^~~~~~~~~
              iswspace_l
prog.cpp:134:64: error: template argument 1 is invalid
              is_same_v<decltype(cout << declval<T>()), ostream&>
                                                                ^
prog.cpp:135:10: error: template argument 2 is invalid
          >
          ^
prog.cpp:136:6: error: expected unqualified-id before ‘>’ token
      > : true_type {};
      ^
prog.cpp: In instantiation of ‘str ToString::bit_vec(T) [with T = std::vector<bool>; str = std::__cxx11::basic_string<char>]’:
prog.cpp:181:38:   required from here
prog.cpp:179:40: error: no matching function for call to ‘ts(std::vector<bool>::reference)’
   str res = "{"; F0R(i,sz(t)) res += ts(t[i]);
                                      ~~^~~~~~
prog.cpp:175:55: note: candidate: ‘template<class T> typename std::enable_if<is_printable_v<T>, std::__cxx11::basic_string<char> >::type ToString::ts(T)’
  tcT> typename enable_if<is_printable_v<T>,str>::type ts(T v) {
                                                       ^~
prog.cpp:175:55: note:   template argument deduction/substitution failed:
prog.cpp: In substitution of ‘template<class T> typename std::enable_if<is_printable_v<T>, std::__cxx11::basic_string<char> >::type ToString::ts(T) [with T = std::_Bit_reference]’:
prog.cpp:179:40:   required from ‘str ToString::bit_vec(T) [with T = std::vector<bool>; str = std::__cxx11::basic_string<char>]’
prog.cpp:181:38:   required from here
prog.cpp:175:55: error: no type named ‘type’ in ‘struct std::enable_if<false, std::__cxx11::basic_string<char> >’
prog.cpp: In instantiation of ‘void Input::re(T&, U& ...) [with T = int; U = {}]’:
prog.cpp:490:22:   required from here
prog.cpp:152:43: error: no matching function for call to ‘re()’
  tcTUU> void re(T& t, U&... u) { re(t); re(u...); } // read multiple
                                         ~~^~~~~~
prog.cpp:152:14: note: candidate: ‘template<class T, class ... U> void Input::re(T&, U& ...)’
  tcTUU> void re(T& t, U&... u) { re(t); re(u...); } // read multiple
              ^~
prog.cpp:152:14: note:   template argument deduction/substitution failed:
prog.cpp:152:43: note:   candidate expects at least 1 argument, 0 provided
  tcTUU> void re(T& t, U&... u) { re(t); re(u...); } // read multiple
                                         ~~^~~~~~
prog.cpp:149:13: note: candidate: ‘template<class T, class U> void Input::re(std::pair<_T1, _T2>&)’
  tcTU> void re(pair<T,U>& p) { re(p.f,p.s); }
             ^~
prog.cpp:149:13: note:   template argument deduction/substitution failed:
prog.cpp:152:43: note:   candidate expects 1 argument, 0 provided
  tcTUU> void re(T& t, U&... u) { re(t); re(u...); } // read multiple
                                         ~~^~~~~~
prog.cpp:146:55: note: candidate: ‘template<class T> typename std::enable_if<is_readable_v<T>, void>::type Input::re(T&)’
  tcT> typename enable_if<is_readable_v<T>,void>::type re(T& x) { cin >> x; } // default
                                                       ^~
prog.cpp:146:55: note:   template argument deduction/substitution failed:
prog.cpp:152:43: note:   candidate expects 1 argument, 0 provided
  tcTUU> void re(T& t, U&... u) { re(t); re(u...); } // read multiple
                                         ~~^~~~~~
prog.cpp:147:12: note: candidate: ‘template<class T> void Input::re(std::complex<_Tp>&)’
  tcT> void re(complex<T>& c) { T a,b; re(a,b); c = {a,b}; } // complex
            ^~
prog.cpp:147:12: note:   template argument deduction/substitution failed:
prog.cpp:152:43: note:   candidate expects 1 argument, 0 provided
  tcTUU> void re(T& t, U&... u) { re(t); re(u...); } // read multiple
                                         ~~^~~~~~
prog.cpp:150:55: note: candidate: ‘template<class T> typename std::enable_if<needs_input_v<T>, void>::type Input::re(T&)’
  tcT> typename enable_if<needs_input_v<T>,void>::type re(T& i) {
                                                       ^~
prog.cpp:150:55: note:   template argument deduction/substitution failed:
prog.cpp:152:43: note:   candidate expects 1 argument, 0 provided
  tcTUU> void re(T& t, U&... u) { re(t); re(u...); } // read multiple
                                         ~~^~~~~~
prog.cpp: In instantiation of ‘void Output::pr_sep(std::ostream&, str, const T&) [with T = long long int; std::ostream = std::basic_ostream<char>; str = std::__cxx11::basic_string<char>]’:
prog.cpp:227:54:   required from ‘void Output::ps(const T& ...) [with T = {long long int}]’
prog.cpp:554:18:   required from here
prog.cpp:220:72: error: no matching function for call to ‘ts(const long long int&)’
  template<class T> void pr_sep(ostream& os, str, const T& t) { os << ts(t); }
                                                                      ~~^~~
prog.cpp:175:55: note: candidate: ‘template<class T> typename std::enable_if<is_printable_v<T>, std::__cxx11::basic_string<char> >::type ToString::ts(T)’
  tcT> typename enable_if<is_printable_v<T>,str>::type ts(T v) {
                                                       ^~
prog.cpp:175:55: note:   template argument deduction/substitution failed:
prog.cpp: In substitution of ‘template<class T> typename std::enable_if<is_printable_v<T>, std::__cxx11::basic_string<char> >::type ToString::ts(T) [with T = long long int]’:
prog.cpp:220:72:   required from ‘void Output::pr_sep(std::ostream&, str, const T&) [with T = long long int; std::ostream = std::basic_ostream<char>; str = std::__cxx11::basic_string<char>]’
prog.cpp:227:54:   required from ‘void Output::ps(const T& ...) [with T = {long long int}]’
prog.cpp:554:18:   required from here
prog.cpp:175:55: error: no type named ‘type’ in ‘struct std::enable_if<false, std::__cxx11::basic_string<char> >’
prog.cpp: In instantiation of ‘void Output::pr_sep(std::ostream&, str, const T&) [with T = long long int; std::ostream = std::basic_ostream<char>; str = std::__cxx11::basic_string<char>]’:
prog.cpp:227:54:   required from ‘void Output::ps(const T& ...) [with T = {long long int}]’
prog.cpp:554:18:   required from here
prog.cpp:181:6: note: candidate: ‘str ToString::ts(V<bool>)’
  str ts(V<bool> v) { return bit_vec(v); }
      ^~
prog.cpp:181:6: note:   no known conversion for argument 1 from ‘const long long int’ to ‘V<bool>’ {aka ‘std::vector<bool>’}
prog.cpp:182:26: note: candidate: ‘template<long unsigned int SZ> str ToString::ts(std::bitset<_Nb>)’
  template<size_t SZ> str ts(bitset<SZ> b) { return bit_vec(b); } // bit vector
                          ^~
prog.cpp:182:26: note:   template argument deduction/substitution failed:
prog.cpp:220:72: note:   mismatched types ‘std::bitset<_Nb>’ and ‘long long int’
  template<class T> void pr_sep(ostream& os, str, const T& t) { os << ts(t); }
                                                                      ~~^~~
prog.cpp:185:12: note: candidate: ‘template<class T, class U> str ToString::ts(std::pair<_T1, _T2>)’
  tcTU> str ts(pair<T,U> p) { return "("+ts(p.f)+", "+ts(p.s)+")"; }
            ^~
prog.cpp:185:12: note:   template argument deduction/substitution failed:
prog.cpp:220:72: note:   mismatched types ‘std::pair<_T1, _T2>’ and ‘long long int’
  template<class T> void pr_sep(ostream& os, str, const T& t) { os << ts(t); }
                                                                      ~~^~~
prog.cpp:195:55: note: candidate: ‘template<class T> typename std::enable_if<needs_output_v<T>, std::__cxx11::basic_string<char> >::type ToString::ts(T)’
  tcT> typename enable_if<needs_output_v<T>,str>::type ts(T v) {
                                                       ^~
prog.cpp:195:55: note:   template argument deduction/substitution failed:
prog.cpp: In substitution of ‘template<class T> typename std::enable_if<needs_output_v<T>, std::__cxx11::basic_string<char> >::type ToString::ts(T) [with T = long long int]’:
prog.cpp:220:72:   required from ‘void Output::pr_sep(std::ostream&, str, const T&) [with T = long long int; std::ostream = std::basic_ostream<char>; str = std::__cxx11::basic_string<char>]’
prog.cpp:227:54:   required from ‘void Output::ps(const T& ...) [with T = {long long int}]’
prog.cpp:554:18:   required from here
prog.cpp:195:55: error: no type named ‘type’ in ‘struct std::enable_if<false, std::__cxx11::basic_string<char> >’
prog.cpp: In function ‘void FileIO::setIn(str)’:
prog.cpp:245:30: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
  void setIn(str s)  { freopen(s.c_str(),"r",stdin); }
                       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
prog.cpp: In function ‘void FileIO::setOut(str)’:
prog.cpp:246:30: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
  void setOut(str s) { freopen(s.c_str(),"w",stdout); }
                       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
stdout
Standard output is empty