submission_id
stringlengths
10
10
problem_id
stringlengths
6
6
language
stringclasses
3 values
code
stringlengths
1
522k
compiler_output
stringlengths
43
10.2k
s048833452
p03702
C++
#include <iostream> #include <cmath> using namespace std; int n,a,b,h[100005]; bool check(long long k) { long long ck=k; for(int i=0;i<n;i++) { if(k*b>=(long long) h[i]); else if(k*a>=(long long) h[i]) { t-=(long long) ceil((double) ((double) (h[i]-k*b))/((double) (a-b))); if(t<0) return false; } else return false; } return true; } int solve() { int lb=-1,rb=1e9; while (lb<rb-1) { int mid=(lb+rb)/(long long)2; if (!check(mid)) { lb=mid; } else { rb=mid; } } return rb; } int main() { cin >> n >> a >> b; for (int i=0;i<n;i++) { cin >> h[i]; } cout << solve(); return 0; }
a.cc: In function 'bool check(long long int)': a.cc:13:25: error: 't' was not declared in this scope 13 | t-=(long long) ceil((double) ((double) (h[i]-k*b))/((double) (a-b))); | ^
s355340846
p03702
C++
#include <iostream> #include <string> #include <algorithm> #include <cstdio> #include <vector> #include <queue> #include <set> #include <numeric> #include <cmath> using namespace std; const long long int mod=1000000009; const long long int INF=1000000000; const long long int MAX=1000000000; int main() { long long int n,a,b; vector<long long int> h; cin>>n>>a>>b; a-=b; h.resize(n); for(int i=0;i<n;i++) { cin>>h[i]; } long long int up=MAX,low=0; long long int mid=0; while(up-low>1) { mid=(up+low)/2; long long int t=0; for(int i=0;i<n;i++) { t+=max(0,(int)(ceil((float)(h[i]-k*b)/(float)a))); } if(t<=mid) { up=mid; }else { low=mid; } } cout<<up<<endl; return 0; }
a.cc: In function 'int main()': a.cc:35:58: error: 'k' was not declared in this scope 35 | t+=max(0,(int)(ceil((float)(h[i]-k*b)/(float)a))); | ^
s476415714
p03702
C++
#include "bits/stdc++.h" using namespace std; #ifdef _DEBUG #include "dump.hpp" #else #define dump(...) #endif #define int long long #define rep(i,a,b) for(int i=(a);i<(b);i++) #define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--) #define all(c) begin(c),end(c) const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f; const int MOD = (int)(1e9) + 7; template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } signed main() { cin.tie(0); ios::sync_with_stdio(false); int N, A, B; cin >> N >> A >> B; vector<int> h(N); rep(i, 0, N) { cin >> h[i]; } auto f = [&](int k) { int x = 0; rep(i, 0, N) { x += max(0, (h[i] - k*B + (A - B - 1)) / (A - B)); dump(x); } return x <= k; }; auto binarySearch = [&](int ng, int ok) { if (f(ng))return ng; while (ng + 1 < ok) { int m = (ng + ok) / 2; if (f(m)) ok = m; else ng = m; } return ok; }; cout << binarySearch(0, 1000000001) << endl; return 0; }
a.cc: In lambda function: a.cc:28:33: error: no matching function for call to 'max(int, __gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type)' 28 | x += max(0, (h[i] - k*B + (A - B - 1)) / (A - B)); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/14/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51, from a.cc:1: /usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)' 257 | max(const _Tp& __a, const _Tp& __b) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed: a.cc:28:33: note: deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'}) 28 | x += max(0, (h[i] - k*B + (A - B - 1)) / (A - B)); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)' 303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate expects 3 arguments, 2 provided In file included from /usr/include/c++/14/algorithm:61: /usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)' 5706 | max(initializer_list<_Tp> __l) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate expects 1 argument, 2 provided /usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)' 5716 | max(initializer_list<_Tp> __l, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5716:5: note: template argument deduction/substitution failed: a.cc:28:33: note: mismatched types 'std::initializer_list<_Tp>' and 'int' 28 | x += max(0, (h[i] - k*B + (A - B - 1)) / (A - B)); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
s956668168
p03702
C++
#include<bits/stdc++.h> using namespace std; int main() { int n; cin>>n; int a,b; cin>>a>>b; float arr[n]; int mx = 0; for(int i = 0;i<n;i++) { cin>>arr[i]; mx += int(ceil(arr[i]/a)); } int mn = 1; while(mn!= mx) { int mid = (mn+mx)/2; int rem = mid; long long int b_cm = mid*b; int i; for( i = 0;i<n;i++) { if(arr[i]> b_cm) { int req = int(ceil((arr[i] - b_cm)/(a-b))); if(req >rem ) break; else rem -= req; } } if(i==n) mx = mid; else mn = mid+1; } cout<<mn;
a.cc: In function 'int main()': a.cc:41:10: error: expected '}' at end of input 41 | cout<<mn; | ^ a.cc:5:1: note: to match this '{' 5 | { | ^
s466865025
p03702
C++
#include "bits/stdc++.h" #define MOD 1000000007 #define INF 11234567890 #define in std::cin #define out std::cout #define rep(i,N) for(int i=0;i<N;++i) typedef long long int LL;   LL N, A, B, h[112345]; LL low, high, mid;   bool check(LL T) { LL res = 0; rep(i, N) { if (h[i] > B*T) { res += (h[i] - B*T) / (A - B); if ((h[i] - B*T) % (A - B) != 0) { ++res; } } } return (res <= T); }   int main() { in >> N >> A >> B; rep(i, N) { in >> h[i]; }   low = 1; high = 1129999934567890; while (high - low > 1) { mid = (high + low) / 2; if (check(mid)) { high = mid; } else { low = mid; } }   out << high << std::endl; return 0; }
a.cc:8:1: error: extended character   is not valid in an identifier 8 |   | ^ a.cc:11:1: error: extended character   is not valid in an identifier 11 |   | ^ a.cc:25:1: error: extended character   is not valid in an identifier 25 |   | ^ a.cc:30:1: error: extended character   is not valid in an identifier 30 |   | ^ a.cc:38:1: error: extended character   is not valid in an identifier 38 |   | ^ a.cc:8:1: error: '\U000000a0' does not name a type 8 |   | ^ a.cc:11:1: error: '\U000000a0' does not name a type 11 |   | ^ a.cc:25:1: error: '\U000000a0' does not name a type 25 |   | ^
s087787431
p03702
C++
#include <iostream> typedef long long in; using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); in a,b,diff,h[123456],mid,l,r,temp,t=0,res; int n; cin>>n>>a>>b; diff=a-b; l=1; r=10e9+10; in res=r; for (int i=0;i<n;i++) cin>>h[i]; while (r-l>1){ mid = (l+r)>>1; t=0; for (int i=0;i<n;i++) { temp = h[i]-b*mid; if (temp>=0) {t+=temp/diff; if (temp%diff!=0) t++; } } if (t>mid) l=mid+1; else r=mid-1,res=mid; } cout<<res; return 0; }
a.cc: In function 'int main()': a.cc:13:8: error: redeclaration of 'in res' 13 | in res=r; | ^~~ a.cc:8:44: note: 'in res' previously declared here 8 | in a,b,diff,h[123456],mid,l,r,temp,t=0,res; | ^~~
s396757049
p03702
C++
#include <iostream> typedef long long in; using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); in a,b,diff,h[123456],mid,l,r,temp,t=0; int n; cin>>n>>a>>b; diff=a-b; l=1; r=10e9+10; for (int i=0;i<n;i++) cin>>h[i]; while (r-l>1){ mid = (l+r)/2; t=0; for (int i=0;i<n;i++) { temp = h[i]-b*mid; if (temp>0) {t+=temp/diff; if (temp%diff!=0) t++; } } if (t>mid) l=mid-1; else r=mid-1; res=mid; } cout<<mid; return 0; }
a.cc: In function 'int main()': a.cc:25:23: error: 'res' was not declared in this scope 25 | else r=mid-1; res=mid; | ^~~
s418723759
p03702
C++
#include <iostream> #include <algorithm> typedef long long ll; #define FOR(i,a,b) for(ll i = (a);i < (b);++i) #define REP(i,n) FOR(i,0,n) #define debug(x) cout << #x << "=" << x << endl; using namespace std; int N,A,B; int enemyLP[100000]; bool check(ll mid){ ll cnt = 0; int addDmg = A-B; int splashDmg = B; REP(i,N){ if(enemyLP[i] > splashDmg * mid){ cnt += ceil((enemyLP[i] - splashDmg * mid) / addDmg); } } if(cnt <= mid){ return true; }else{ return false; } } int main(void){ cin >> N >> A >> B; REP(i,N){ cin >> enemyLP[i]; } int ok = (int)1e+9; int ng = -1; while(abs(ok - ng) > 1){ ll mid = (ok + ng) / 2; if(check(mid)){ ok = mid; }else{ ng = mid; } } cout << ok << endl; return 0; }
a.cc: In function 'bool check(ll)': a.cc:25:20: error: 'ceil' was not declared in this scope 25 | cnt += ceil((enemyLP[i] - splashDmg * mid) / addDmg); | ^~~~
s928022905
p03702
C++
#define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<vector> #include<queue> #include<map> #include<stdio.h> #include<string.h> #include<string> #include<string> #include<set> #include<stdlib.h> #include<bitset> #include<algorithm> using namespace std; #define ll long long int n,a,b; vector<int>v; bool check(long long x) { long long sum = 0; for (int i = 0; i < n; ++i) { if (b*x >= v[i]) continue; // x == y + z // v[i] <= a*y + b*z // v[i] <= a*y +(b*(x-y)) // v[i] <= a*y + b*x -b*y // v[i] -b*x <= y*(a-b) // y = (v[i] - b*x)/(a-b) sum += max((ll)0, (ll)ceil((double)(v[i] - b*x) / (a - b))); } return sum <= x; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); #endif // !ONLINE_JUDGE int x; scanf("%d%d%d", &n, &a, &b); long long d = 0; for (int i = 0; i < n; ++i) { scanf("%d", &x); v.push_back(x); d += x / a + (x%a?1:0); } long long low = 0, high = d, mid, ans = d; while (low <= high) { mid = (low + high) / 2; if (check(mid)) { ans = mid; high = mid - 1; } else low = mid + 1; } cout << ans << endl; }
a.cc: In function 'bool check(long long int)': a.cc:29:39: error: 'ceil' was not declared in this scope 29 | sum += max((ll)0, (ll)ceil((double)(v[i] - b*x) / (a - b))); | ^~~~
s195767313
p03702
C++
#include<iostream> #include <algorithm> #include <vector> #include <deque> #include <queue> using namespace std; int main() { // 整数の入力 long long remain,i,N,temp,A,B,kari,remainCount,ACount,total,minBOnly,BOnlyCount,maxAOnly,AOnlyCount,minHP; bool endFlag = false; maxAOnly = 0; vector<long long> hitpoints; cin >> N >> A >> B; for (i=0;i<N;i++){ cin >> temp; hitpoints.push_back(temp); AOnlyCount = temp/ A + (temp % A != 0); if (AOnlyCount > maxAOnly){ maxAOnly = AOnlyCount; } } sort(hitpoints.begin(),hitpoints.end(),greater<long long>()); total = maxAOnly; ACount = 0; for (i=0;i<N;i++){ hitpoints[i]+= - maxAOnly*B; if (hitpoints[i] > 0){ ACount += hitpoints[i] / (A - B) + (hitpoints[i] % (A - B) != 0); } } if (ACount <= total){ endFlag = true; } while (!endFlag){ remain = - total * (A - B); remainCount = 0; ACount = 0; minBOnly = 1000000001; minHP = 1000000001; for (i=0;i<N;i++){ if (hitpoints[i] > 0){ remain += hitpoints[i]; BOnlyCount = hitpoints[i] / B + (hitpoints[i] % B != 0); minHP = hitpoints[i]; if (BOnlyCount < minBOnly){ minBOnly = BOnlyCount; } remainCount +=1; }else{ break; } } kari = max({remain / (A + (remainCount-1) * B) + (remain % (A + (remainCount-1) * B) != 0), min(minBOnly,remainCount - total)}, (minHP + total * B)/(A + (remainCount-1) * B) * remainCount ); total += kari; for (i=0;i<N;i++){ hitpoints[i]+= - kari*B; if (hitpoints[i] > 0){ ACount += hitpoints[i] / (A - B) + (hitpoints[i] % (A - B) != 0); }else{ break; } } if (ACount <= total){ endFlag = true; } } cout << total << endl; return 0; }
In file included from /usr/include/c++/14/bits/stl_algobase.h:71, from /usr/include/c++/14/string:51, from /usr/include/c++/14/bits/locale_classes.h:40, from /usr/include/c++/14/bits/ios_base.h:41, from /usr/include/c++/14/ios:44, from /usr/include/c++/14/ostream:40, from /usr/include/c++/14/iostream:41, from a.cc:1: /usr/include/c++/14/bits/predefined_ops.h: In instantiation of 'constexpr bool __gnu_cxx::__ops::_Iter_comp_iter<_Compare>::operator()(_Iterator1, _Iterator2) [with _Iterator1 = const long long int*; _Iterator2 = const long long int*; _Compare = long long int]': /usr/include/c++/14/bits/stl_algo.h:5626:12: required from 'constexpr _ForwardIterator std::__max_element(_ForwardIterator, _ForwardIterator, _Compare) [with _ForwardIterator = const long long int*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<long long int>]' 5626 | if (__comp(__result, __first)) | ~~~~~~^~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_algo.h:5719:44: required from 'constexpr _Tp std::max(initializer_list<_Tp>, _Compare) [with _Tp = long long int; _Compare = long long int]' 5719 | return *_GLIBCXX_STD_A::__max_element(__l.begin(), __l.end(), | ^ a.cc:60:19: required from here 60 | kari = max({remain / (A + (remainCount-1) * B) + (remain % (A + (remainCount-1) * B) != 0), | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 61 | min(minBOnly,remainCount - total)}, | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 62 | (minHP + total * B)/(A + (remainCount-1) * B) * remainCount ); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/predefined_ops.h:158:30: error: expression cannot be used as a function 158 | { return bool(_M_comp(*__it1, *__it2)); } | ~~~~~~~^~~~~~~~~~~~~~~~
s295184200
p03702
C++
#include <bits/stdc++.h> #define ALL(a) (a).begin(),(a).end() #define FOR(i,a,b) for(int i=(a);i<(b);i++) #define rep(i,n) FOR(i,0,n) #define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--) #define rrep(i,n) RFOR(i,n,0) #define DEBUG(x) cout<<#x<<": "<<x<<endl #define vint vector<int> #define vdbl vector<double> #define vstr vector<string> using namespace std; typedef long long ll; typedef unsigned long long ull; ll N,A,B; ll h[100001]; bool C(ll x){ ll l = x; rep(i,N){ ll a = h[i]; if(a <= B*x){ continue; } ll b = a - B*x; ll c = b % (A-B) == 0 ? b / (A-B) : b / (A-B) + 1; l -= c; if(l < 0) return false; } return true; } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N >> A >> B; sum = 0; rep(i,N){ cin >> h[i]; } ll lb = 0; ll ub = 1e10; while(ub - lb > 1){ ll mid = (lb + ub) / 2; // cout << lb << "," << mid << "," << ub << "," << C(mid) << endl; if(C(mid)) ub = mid; else lb = mid; } cout << ub << endl; }
a.cc: In function 'int main()': a.cc:46:9: error: 'sum' was not declared in this scope 46 | sum = 0; | ^~~
s117440974
p03702
C++
// ARC057-D.cpp : コンソール アプリケーションのエントリ ポイントを定義します。 // #include "stdafx.h" #include <iostream> #include <vector> #include <algorithm> #include <functional> using namespace std; #define int long long #define INF (int)(1e9 + 7) int n, a, b; vector<int> h; signed main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n >> a >> b; h.resize(n); for (int i = 0; i < n; ++i) { cin >> h[i]; } sort(h.begin(), h.end(), greater<int>()); int l = 0, r = INF, dif = a - b, t = 0, m, tmp; for (;;) { t = m = 0; for (int i = 0; i < n; ++i) { m = h[i] - b * l; if (m > 0) { t += (m % dif == 0) ? m / dif : m / dif + 1; } else if (m <= 0) break; } if (t <= l) { l += (r - l) / 2; if (r - l < 10) break; continue; } t = m = 0; for (int i = 0; i < n; ++i) { m = h[i] - b * r; if (m > 0) { t += (m % dif == 0) ? m / dif : m / dif + 1; } else if (m <= 0) break; } if (t <= r) { r -= (r - l) / 2; if (r - l < 10) break; continue; } tmp = r; r += (r - l); l = tmp + 1; } int ans = INF; l = (l - 10 > 0) ? l - 10 : 0; r = (r + 10 < INF) ? r + 10 : r; for (int i = l; i <= r; ++i) { t = m = 0; for (int j = 0; j < n; ++j) { m = h[j] - b * i; if (m > 0) { t += (m % dif == 0) ? m / dif : m / dif + 1; } else if (m <= 0) break; } if (t <= i) { ans = (ans > i) ? i : ans; } } cout << ans << endl; return 0; }
a.cc:4:10: fatal error: stdafx.h: No such file or directory 4 | #include "stdafx.h" | ^~~~~~~~~~ compilation terminated.
s116868281
p03702
C++
#include <iostream> #include <cstdio> #include <cmath> #include <cstdio> #include <cstring> #include <string> #include <vector> #include <set> #include <map> #include <stack> #include <queue> #include <algorithm> #define CK(N,A,B) (A<=N&&N<B) #define REP(i,a,b) for(int i=a;i<b;i++) #define RREP(i,a,b) for(int i=(b-1);a<=i;i--) #define F first #define S second #define ll long long; const int INF = 1e9; const long long LLINF = 1e15; using namespace std; long long N, A, B, H[100010]; bool check(long long k){ long long sum = 0; REP(i,0,N) sum += max(0, (H[i]-k*B+(A-B-1))/(A-B)); return (sum <= k); } int main() { cin>>N>>A>>B; REP(i,0,N) cin>>H[i]; long long l = 0, r = 1e9; while(r-l > 1){ long long mid = (l+r)/2; if(check(mid)) r = mid; else l = mid; } cout<<r<<endl; return 0; }
a.cc: In function 'bool check(long long int)': a.cc:30:27: error: no matching function for call to 'max(int, long long int)' 30 | REP(i,0,N) sum += max(0, (H[i]-k*B+(A-B-1))/(A-B)); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/14/string:51, from /usr/include/c++/14/bits/locale_classes.h:40, from /usr/include/c++/14/bits/ios_base.h:41, from /usr/include/c++/14/ios:44, from /usr/include/c++/14/ostream:40, from /usr/include/c++/14/iostream:41, from a.cc:1: /usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)' 257 | max(const _Tp& __a, const _Tp& __b) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed: a.cc:30:27: note: deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int') 30 | REP(i,0,N) sum += max(0, (H[i]-k*B+(A-B-1))/(A-B)); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)' 303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate expects 3 arguments, 2 provided In file included from /usr/include/c++/14/algorithm:61, from a.cc:12: /usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)' 5706 | max(initializer_list<_Tp> __l) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate expects 1 argument, 2 provided /usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)' 5716 | max(initializer_list<_Tp> __l, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5716:5: note: template argument deduction/substitution failed: a.cc:30:27: note: mismatched types 'std::initializer_list<_Tp>' and 'int' 30 | REP(i,0,N) sum += max(0, (H[i]-k*B+(A-B-1))/(A-B)); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
s263256546
p03702
C++
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n; ll a, b, h[100000]; int can(ll k){ ll s = 0; for(int i = 0; i < n; i++){ s += max(0, ((h[i] - a * k) + b - 1) / b); if(s > k) return 0; } return 1; } int main(){ scanf("%d%lld%lld", &n, &a, &b); for(int i = 0; i < n; i++) scanf("%lld", h + i); ll s = 1, e = int(1e14) + 5; while(s <= e){ ll m = (s + e) / 2; if(can(m)) e = m - 1; else s = m + 1; } printf("%lld\n", s); }
a.cc: In function 'int can(ll)': a.cc:11:25: error: no matching function for call to 'max(int, ll)' 11 | s += max(0, ((h[i] - a * k) + b - 1) / b); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/14/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51, from a.cc:1: /usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)' 257 | max(const _Tp& __a, const _Tp& __b) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed: a.cc:11:25: note: deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'}) 11 | s += max(0, ((h[i] - a * k) + b - 1) / b); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)' 303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate expects 3 arguments, 2 provided In file included from /usr/include/c++/14/algorithm:61: /usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)' 5706 | max(initializer_list<_Tp> __l) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate expects 1 argument, 2 provided /usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)' 5716 | max(initializer_list<_Tp> __l, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5716:5: note: template argument deduction/substitution failed: a.cc:11:25: note: mismatched types 'std::initializer_list<_Tp>' and 'int' 11 | s += max(0, ((h[i] - a * k) + b - 1) / b); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
s705705614
p03702
C++
#include<iostream> #include<fstream> #include<stdio.h> #include<string> #include<vector> #include<map> #include<math.h> #include<algorithm> #include<iomanip> #include<set> using namespace std; int n; long long a, b, c, ans = 0; vector<long long> h; bool f(long long aa) { long long an= 0; for (int i = 0; i < n; i++) { long long d = h[i] - aa*b; if (d > 0) { an += (d+c-1) / c); } } return an <= aa; } int main() { cin >> n >> a >> b; c = a - b; h.resize(n); for (int i = 0; i < n; i++) { cin >> h[i]; } long long mm = 1, ma = 17179869185; long long now = (mm + ma)/2; while (ma - mm > 1) { // cout << mm << " " << now << " " << ma <<endl; if (f(now)) { ma = now; } else { mm = now; } now = (mm + ma) / 2; } cout << ma << endl; // cin >> n; return 0; }
a.cc: In function 'bool f(long long int)': a.cc:23:42: error: expected ';' before ')' token 23 | an += (d+c-1) / c); | ^ | ;
s576798869
p03702
C++
#include<iostream> #include<fstream> #include<stdio.h> #include<string> #include<vector> #include<map> #include<math.h> #include<algorithm> #include<iomanip> #include<set> using namespace std; int n; long long a, b, c, ans = 0; vector<long long> h; bool f(long long aa) { long long an= 0; for (int i = 0; i < n; i++) { long long d = h[i] - aa*b; if (d > 0) { an += ceil(double(d) / c); } } return an <= aa; } int main() { cin >> n >> a >> b; c = a - b; h.resize(n); for (int i = 0; i < n; i++) { cin >> h[i]; } long long mm = 1, ma = 17179869185; long long now = (mm + ma)/2; while (ma - mm > 2) { // cout << mm << " " << now << " " << ma <<endl; if (f(now)) { ma = now + 1; } else { mm = now; } now = (mm + ma) / 2; } if(f(m)) cout << mm << endl; else cout << mm + 1 << endl; // cin >> n; return 0; }
a.cc: In function 'int main()': a.cc:48:6: error: 'm' was not declared in this scope; did you mean 'ma'? 48 | if(f(m)) cout << mm << endl; | ^ | ma
s926619863
p03702
C++
#include <bits/stdc++.h> using namespace std; int main(){ long long int n,a,b; cin>>n>>a>>b; long long int h[n]; for(int i=0;i<n;++i){ cin>>h[i]; } long long int l = -1, r = (long long int)1e9; while(r-l>1){ long long int m=(l+r)/2; long long int req=0; for(int i=0;i<n;++i){ if(h[i]>(long long)m*(long long)b){ if(h[i]-m*b < a-b)res++; else if(h[i]-m*b % (a-b) ==0)res+=(h[i]-m*b)/(a-b); else req+=(h[i]-(long long)m*(long long int)b)/(a-b) + 1; } } if(req<=m){ r=m; } else { l=m; } } cout<<r<<endl; return 0; }
a.cc: In function 'int main()': a.cc:16:43: error: 'res' was not declared in this scope; did you mean 'req'? 16 | if(h[i]-m*b < a-b)res++; | ^~~ | req a.cc:17:54: error: 'res' was not declared in this scope; did you mean 'req'? 17 | else if(h[i]-m*b % (a-b) ==0)res+=(h[i]-m*b)/(a-b); | ^~~ | req
s951143516
p03702
C++
#include <iostream> #include <vector> using namespace std; void display(); vector<long long> v; int main(int argc, const char * argv[]) { long long n, a, b; long long x; long long cnt, num; //初期化 cnt = 0; cin >> n >> a >> b; for (long long i = 0; i < n; i++) { cin >> x; v.push_back(x); } while (v.empty() != true) { sort(v.begin(), v.end()); num = -1; v[v.size()-1] -= a; if (v[v.size()-1] <= 0) { v.erase(v.end()-1); } for (long long i = v.size()-1; i >= 0; i--) { if (v[i] - b > 0) { v[i] -= b; }else{ num = i; break; } } //要素削除 if (num != -1) { v.erase(v.begin(), v.begin()+num); } cnt++; } cout << cnt << endl; return 0; } void display() { for (long long i = 0; i < v.size(); i++) { cout << v[i] << ' '; } cout << endl; }
a.cc: In function 'int main(int, const char**)': a.cc:27:9: error: 'sort' was not declared in this scope; did you mean 'short'? 27 | sort(v.begin(), v.end()); | ^~~~ | short
s301901622
p03702
C++
int main() { ll N, A, B, Diff, h[100002]; scanf("%lld %lld %lld", &N, &A, &B); Diff = A - B; for (int i = 0; i < N; i++) scanf("%lld", h + i); std::sort(h, h + N); h[N] = 0x7fffffffffffffffll; ll up = 1000000000, down = 0, center = (up + down) / 2; while (1 < (up - down)) { ll adown; for (adown = 0; h[adown] < (B * center); adown++); ll sum = 0; for (int i = adown; i < N; i++) sum += ((h[i] - B * center) + Diff - 1) / Diff; if (sum <= center) up = center; else down = center; center = (up + down) / 2; } printf("%d\n", up); }
a.cc: In function 'int main()': a.cc:2:9: error: 'll' was not declared in this scope 2 | ll N, A, B, Diff, h[100002]; | ^~ a.cc:3:34: error: 'N' was not declared in this scope 3 | scanf("%lld %lld %lld", &N, &A, &B); | ^ a.cc:3:38: error: 'A' was not declared in this scope 3 | scanf("%lld %lld %lld", &N, &A, &B); | ^ a.cc:3:42: error: 'B' was not declared in this scope 3 | scanf("%lld %lld %lld", &N, &A, &B); | ^ a.cc:3:9: error: 'scanf' was not declared in this scope 3 | scanf("%lld %lld %lld", &N, &A, &B); | ^~~~~ a.cc:4:9: error: 'Diff' was not declared in this scope 4 | Diff = A - B; | ^~~~ a.cc:6:31: error: 'h' was not declared in this scope 6 | scanf("%lld", h + i); | ^ a.cc:8:14: error: 'sort' is not a member of 'std' 8 | std::sort(h, h + N); | ^~~~ a.cc:8:19: error: 'h' was not declared in this scope 8 | std::sort(h, h + N); | ^ a.cc:10:11: error: expected ';' before 'up' 10 | ll up = 1000000000, down = 0, center = (up + down) / 2; | ^~~ | ; a.cc:11:21: error: 'up' was not declared in this scope 11 | while (1 < (up - down)) { | ^~ a.cc:11:26: error: 'down' was not declared in this scope 11 | while (1 < (up - down)) { | ^~~~ a.cc:12:19: error: expected ';' before 'adown' 12 | ll adown; | ^~~~~~ | ; a.cc:13:22: error: 'adown' was not declared in this scope 13 | for (adown = 0; h[adown] < (B * center); adown++); | ^~~~~ a.cc:13:49: error: 'center' was not declared in this scope 13 | for (adown = 0; h[adown] < (B * center); adown++); | ^~~~~~ a.cc:15:19: error: expected ';' before 'sum' 15 | ll sum = 0; | ^~~~ | ; a.cc:16:30: error: 'adown' was not declared in this scope 16 | for (int i = adown; i < N; i++) | ^~~~~ a.cc:17:25: error: 'sum' was not declared in this scope 17 | sum += ((h[i] - B * center) + Diff - 1) / Diff; | ^~~ a.cc:17:45: error: 'center' was not declared in this scope 17 | sum += ((h[i] - B * center) + Diff - 1) / Diff; | ^~~~~~ a.cc:19:21: error: 'sum' was not declared in this scope 19 | if (sum <= center) | ^~~ a.cc:19:28: error: 'center' was not declared in this scope 19 | if (sum <= center) | ^~~~~~ a.cc:23:17: error: 'center' was not declared in this scope 23 | center = (up + down) / 2; | ^~~~~~ a.cc:26:24: error: 'up' was not declared in this scope 26 | printf("%d\n", up); | ^~ a.cc:26:9: error: 'printf' was not declared in this scope 26 | printf("%d\n", up); | ^~~~~~ a.cc:1:1: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>' +++ |+#include <cstdio> 1 | int main() {
s122847950
p03702
C++
#include <bits/stdc++.h> #define ALL(a) (a).begin(),(a).end() #define FOR(i,a,b) for(int i=(a);i<(b);i++) #define rep(i,n) FOR(i,0,n) #define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--) #define rrep(i,n) RFOR(i,n,0) #define DEBUG(x) cout<<#x<<": "<<x<<endl #define vint vector<int> #define vdbl vector<double> #define vstr vector<string> using namespace std; typedef long long ll; typedef unsigned long long ull; ll N,A,B; ll h[100001]; ll sum; bool C(ll x){ ll l = x; rep(i,N){ ll a = h[i]; if(a <= B*x){ continue; } ll b = a - B*x; ll c = b % (A-B) == 0 ? b / (A-B) : b / (A-B) + 1; l -= c; if(l < 0) return false; } return true; } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N >> A >> B; sum = 0; rep(i,N){ cin >> h[i]; sum += h[i]; } ll cnt = 0; rep(i,N) { if(h[i] <= B) cnt++; } if(cnt == N){ cout << 1 << end; return 0; } ll lb = 0; ll ub = 1e14; while(ub - lb > 1){ ll mid = (lb + ub) / 2; // cout << lb << "," << mid << "," << ub << "," << C(mid) << endl; if(C(mid)) ub = mid; else lb = mid; } cout << ub << endl; }
a.cc: In function 'int main()': a.cc:58:27: error: no match for 'operator<<' (operand types are 'std::basic_ostream<char>' and '<unresolved overloaded function type>') 58 | cout << 1 << end; | ~~~~~~~~~~^~~~~~ In file included from /usr/include/c++/14/istream:41, from /usr/include/c++/14/sstream:40, from /usr/include/c++/14/complex:45, from /usr/include/c++/14/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127, from a.cc:1: /usr/include/c++/14/ostream:116:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(__ostream_type& (*)(__ostream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]' 116 | operator<<(__ostream_type& (*__pf)(__ostream_type&)) | ^~~~~~~~ /usr/include/c++/14/ostream:116:36: note: no known conversion for argument 1 from '<unresolved overloaded function type>' to 'std::basic_ostream<char>::__ostream_type& (*)(std::basic_ostream<char>::__ostream_type&)' {aka 'std::basic_ostream<char>& (*)(std::basic_ostream<char>&)'} 116 | operator<<(__ostream_type& (*__pf)(__ostream_type&)) | ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/ostream:125:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(__ios_type& (*)(__ios_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>; __ios_type = std::basic_ios<char>]' 125 | operator<<(__ios_type& (*__pf)(__ios_type&)) | ^~~~~~~~ /usr/include/c++/14/ostream:125:32: note: no known conversion for argument 1 from '<unresolved overloaded function type>' to 'std::basic_ostream<char>::__ios_type& (*)(std::basic_ostream<char>::__ios_type&)' {aka 'std::basic_ios<char>& (*)(std::basic_ios<char>&)'} 125 | operator<<(__ios_type& (*__pf)(__ios_type&)) | ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~ /usr/include/c++/14/ostream:135:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]' 135 | operator<<(ios_base& (*__pf) (ios_base&)) | ^~~~~~~~ /usr/include/c++/14/ostream:135:30: note: no known conversion for argument 1 from '<unresolved overloaded function type>' to 'std::ios_base& (*)(std::ios_base&)' 135 | operator<<(ios_base& (*__pf) (ios_base&)) | ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~ /usr/include/c++/14/ostream:174:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]' 174 | operator<<(long __n) | ^~~~~~~~ /usr/include/c++/14/ostream:174:23: note: no known conversion for argument 1 from '<unresolved overloaded function type>' to 'long int' 174 | operator<<(long __n) | ~~~~~^~~ /usr/include/c++/14/ostream:178:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]' 178 | operator<<(unsigned long __n) | ^~~~~~~~ /usr/include/c++/14/ostream:178:32: note: no known conversion for argument 1 from '<unresolved overloaded function type>' to 'long unsigned int' 178 | operator<<(unsigned long __n) | ~~~~~~~~~~~~~~^~~ /usr/include/c++/14/ostream:182:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]' 182 | operator<<(bool __n) | ^~~~~~~~ /usr/include/c++/14/ostream:182:23: note: no known conversion for argument 1 from '<unresolved overloaded function type>' to 'bool' 182 | operator<<(bool __n) | ~~~~~^~~ In file included from /usr/include/c++/14/ostream:1022: /usr/include/c++/14/bits/ostream.tcc:96:5: note: candidate: 'std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = char; _Traits = std::char_traits<char>]' 96 | basic_ostream<_CharT, _Traits>:: | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/ostream.tcc:97:22: note: no known conversion for argument 1 from '<unresolved overloaded function type>' to 'short int' 97 | operator<<(short __n) | ~~~~~~^~~ /usr/include/c++/14/ostream:189:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]' 189 | operator<<(unsigned short __n) | ^~~~~~~~ /usr/include/c++/14/ostream:189:33: note: no known conversion for argument 1 from '<unresolved overloaded function type>' to 'short unsigned int' 189 | operator<<(unsigned short __n) | ~~~~~~~~~~~~~~~^~~ /usr/include/c++/14/bits/ostream.tcc:110:5: note: candidate: 'std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char; _Traits = std::char_traits<char>]' 110 | basic_ostream<_CharT, _Traits>:: | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/ostream.tcc:111:20: note: no known conversion for argument 1 from '<unresolved overloaded function type>' to 'int' 111 | operator<<(int __n) | ~~~~^~~ /usr/include/c++/14/ostream:200:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]' 200 | operator<<(unsigned int __n) | ^~~~~~~~ /usr/include/c++/14/ostream:200:31: note: no known conversion for argument 1 from '<unresolved overloaded function type>' to 'unsigned int' 200 | operator<<(unsigned int __n) | ~~~~~~~~~~~~~^~~ /usr/include/c++/14/ostream:211:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]' 211 | operator<<(long long __n) | ^~~~~~~~ /usr/include/c++/14/ostream:211:28: note: no known conversion for argument 1 from '<unresolved overloaded function type>' to 'long long int' 211 | operator<<(long long __n) | ~~~~~~~~~~^~~ /usr/include/c++/14/ostream:215:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]' 215 | operator<<(unsigned long long __n) | ^~~~~~~~ /usr/include/c++/14/ostream:215:37: note: no known conversion for argument 1 from '<unresolved overloaded function type>' to 'long long unsigned int' 215 | operator<<(unsigned long long __n) | ~~~~~~~~~~~~~~~~~~~^~~ /usr/include/c++/14/ostream:231:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]' 231 | operator<<(double __f) | ^~~~~~~~ /usr/include/c++/14/ostream:231:25: note: no known conversion for argument 1 from '<unresolved overloaded function type>' to 'double' 231 | operator<<(double __f) | ~~~~~~~^~~ /usr/include/c++/14/ostream:235:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(float) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]' 235 | operator<<(float __f) | ^~~~~~~~ /usr/include/c++/14/ostream:235:24: note: no known conversion for argument 1 from '<unresolved overloaded function type>' to 'float' 235 | operator<<(float __f) | ~~~~~~^~~ /usr/include/c++/14/ostream:243:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long double) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]' 243 | operator<<(long double __f) | ^~~~~~~~ /usr/include/c++/14/ostream:243:30: note: no known conversion for argument 1 from '<unresolved overloaded function type>' to 'long double' 243 | operator<<(long double __f) | ~~~~~~~~~~~~^~~ /usr/include/c++/14/ostream:301:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(const void*) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]' 301 | operator<<(const void* __p) | ^~~~~~~~ /usr/include/c++/14/ostream:301:30: note: no known conversion for argument 1 from '<unresolved overloaded function type>' to 'const void*' 301 | operator<<(const void* __p) | ~~~~~~~~~~~~^~~ /usr/include/c++/14/ostream:306:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::nullptr_t) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>; std::nullptr_t = std::null
s658830432
p03702
C++
#include <iostream> #include <algorithm> using namespace std; int main(){ int n,a,b; cin >> n >> a >> b; int h[n]; for(int i=0;i<n;i++){ cin >> h[i]; } sort(h,h+n); int ans=1; int x=0; bool flag=false; while(){ while(h[x]<=ans*b){ x++; if(x>=n-1){ flag=true; break; } } if(flag=true){ break; } h[n-1]-=(a-b); sort(h,h+n); ans++; } cout << ans <<endl; }
a.cc: In function 'int main()': a.cc:18:9: error: expected primary-expression before ')' token 18 | while(){ | ^
s428300832
p03702
C++
#include <iostream> using namespace std; int main(void){ int n,a,b; int h[100000]; int m=0; bool f; cin >> n >> a >> b; for (int i=0; i<n; i++) cin >> h[i]; while(1){ f=1; sort(h,h+n); h[n-1] -= a; if(h[n-1]>0) f=0; for (int i=0; i<n-1; i++){ h[i] -= b; if(h[i]>0) f=0; } m += 1; if(f==1){ cout << m << endl; return 0; } } }
a.cc: In function 'int main()': a.cc:14:5: error: 'sort' was not declared in this scope; did you mean 'short'? 14 | sort(h,h+n); | ^~~~ | short
s510704997
p03702
C++
#include <stdio.h> #include <algorithm> using ll = long long; int main() { ll N, A, B, Diff, h[100001]; scanf("%lld %lld %lld", &N, &A, &B); Diff = A - B; for (int i = 0; i < N; i++) scanf("%lld", h + i); std::sort(h, h + N); h[N] = LLONG_MAX; ll up = 1000000000, down = 0, center = (up + down) / 2; while (1 < (up - down)) { ll aup = N + 1, adown = 0, acenter = (aup + adown) / 2; while (1 < (aup - adown)) { if (h[adown] < (B * center)) adown = acenter; else aup = acenter; acenter = (aup + adown) / 2; } ll sum = 0; for (int i = adown + 1; i < N; i++) sum += (h[i] - B * center + Diff - 1) / Diff; if (sum <= center) up = center; else down = center; center = (up + down) / 2; } printf("%d\n", up); }
a.cc: In function 'int main()': a.cc:13:16: error: 'LLONG_MAX' was not declared in this scope 13 | h[N] = LLONG_MAX; | ^~~~~~~~~ a.cc:3:1: note: 'LLONG_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>' 2 | #include <algorithm> +++ |+#include <climits> 3 |
s152333375
p03702
C++
#include <iostream> #include <sstream> #include <vector> #include <map> #include <set> #include <algorithm> #include <queue> #include <stack> #include <cfloat> #include <cmath> #include <functional> #include <forward_list> #include <list> #define DEBUG(x) cout << #x << "\t:" << x << endl; #define EPS (1e-9) #define INF (INT_MAX/2) #define MOD 1000000007 #define PI 3.14159265358979 #define REP(i,n) for(int i = 0; i < (n); ++i) #define REPV(it,v) for(auto it = (v).begin(); it != (v).end(); ++it) #define NUM 5000 #define ll long long #define ull unsigned long long using namespace std; typedef pair<int, int> iiPair; class Main { public: bool winnable(vector<int>& hs, ll n, int a, int b) { ll sum = 0; REP(i, hs.size()) { int rest = hs[i] - n * b; int more = a - b; sum += (rest + more - 1) / more; } bool res = (sum <= n); return res; } int getAns(vector<int>& hs, int a, int b) { int left = 0; int right = INT_MAX/2; while (right - left > 1) { int mid = ((ll)left + right) / 2; if (winnable(hs, mid, a, b)) { right = mid; } else { left = mid; } } return right; } }; int main(void) { Main main; int n,a,b; vector<int> hs; cin >> n >> a >> b; REP(i, n) { int inp; cin >> inp; hs.push_back(inp); } cout << main.getAns(hs, a, b) << endl; return 0; }
a.cc: In member function 'int Main::getAns(std::vector<int>&, int, int)': a.cc:49:29: error: 'INT_MAX' was not declared in this scope 49 | int right = INT_MAX/2; | ^~~~~~~ a.cc:14:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>' 13 | #include <list> +++ |+#include <climits> 14 |
s521929965
p03702
C++
5 2 1 900000000 900000000 1000000000 1000000000 1000000000 ----------- この上が 読み込む データ この下は自由に 使える
a.cc:1:1: error: expected unqualified-id before numeric constant 1 | 5 2 1 | ^
s809234829
p03702
C++
#include<cstdio> #include<algorithm> #include<queue> #include<iostream> using namespace std; const int N=1e5+1e3+7; const long long M=1e10+1e3+7; long long n,a,b,h[N],ans,dam,k,hh[N]; bool can(long long m) { ans=0; memset(hh,0,sizeof(hh)); for(int i=1;i<=n;i++) hh[i]=h[i]-b*m; for(int i=1;i<=n;i++) { if(hh[i]<=0) continue; else { if(hh[i]%a) ans+=hh[i]/(a-b)+1; else ans+=hh[i]/(a-b); } } return ans<=m; } int main() { cin>>n>>a>>b; for(int i=1;i<=n;i++) cin>>h[i]; long long l=0,r=M+1; while(r-l>1) { long long mid=(l+r)>>1; if(can(mid)) r=mid; else l=mid; } cout<<r; }
a.cc: In function 'bool can(long long int)': a.cc:16:9: error: 'memset' was not declared in this scope 16 | memset(hh,0,sizeof(hh)); | ^~~~~~ a.cc:5:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>' 4 | #include<iostream> +++ |+#include <cstring> 5 | using namespace std;
s724947194
p03702
C++
#include<cstdio> #include<algorithm> #include<queue> #include<iostream> using namespace std; const int N=1e5+1e3+7; const long long M=1e10+1e3+7; long long n,a,b,h[N],ans,dam,k,hh[N]; bool can(int m) { ans=0; memset(hh,0,sizeof(hh)); for(int i=1;i<=n;i++) hh[i]=h[i]-b*m; for(int i=1;i<=n;i++) { if(hh[i]<=0) continue; else { if(hh[i]%a) ans+=hh[i]/(a-b)+1; else ans+=hh[i]/(a-b); } } return ans<=m; } int main() { cin>>n>>a>>b; for(int i=1;i<=n;i++) cin>>h[i]; long long l=0,r=M+1; while(r-l>1) { long long mid=(l+r)>>1; if(can(mid)) r=mid; else l=mid; } cout<<r; }
a.cc: In function 'bool can(int)': a.cc:16:9: error: 'memset' was not declared in this scope 16 | memset(hh,0,sizeof(hh)); | ^~~~~~ a.cc:5:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>' 4 | #include<iostream> +++ |+#include <cstring> 5 | using namespace std;
s409001752
p03702
C++
#include<cstdio> #include<algorithm> #include<queue> #include<iostream> using namespace std; const int N=1e5+1e3+7; const long long M=1e10+1e3+7; long long n,a,b,h[N],ans,dam,k,hh[N]; bool can(int m) { ans=0; memset(hh,0,sizeof(hh)); for(int i=1;i<=n;i++) hh[i]=h[i]-b*m; for(int i=1;i<=n;i++) { if(hh[i]<=0) continue; else { if(hh[i]%a) ans+=hh[i]/(a-b)+1; else ans+=hh[i]/(a-b); } } return ans<=m; } int main() { cin>>n>>a>>b; for(int i=1;i<=n;i++) cin>>h[i]; long long l=0,r=M+1; while(r-l>1) { int mid=(l+r)>>1; if(can(mid)) r=mid; else l=mid; } cout<<r; }
a.cc: In function 'bool can(int)': a.cc:16:9: error: 'memset' was not declared in this scope 16 | memset(hh,0,sizeof(hh)); | ^~~~~~ a.cc:5:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>' 4 | #include<iostream> +++ |+#include <cstring> 5 | using namespace std;
s849584149
p03702
C++
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdint> #include <cstdio> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <tuple> #include <utility> #include <vector> using namespace std; using int64 = int64_t; int64 N, A, B; int64 h[100000]; int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N >> A >> B; for (int j = 0; j < N; ++j) { cin >> h[j]; } int64 l = 0, r = 1000000001; while (l < r) { int64 m = (l + r) / 2; int64 D = A-B, b = 0; for (int j = 0; j < N; ++j) { int64 tt = max(0LL, h[j] - B * m); b += (tt + D - 1) / D; } if (b <= m) { r = m; } else { l = m+1; } } cout << r << endl; return 0; }
a.cc: In function 'int main()': a.cc:41:27: error: no matching function for call to 'max(long long int, int64)' 41 | int64 tt = max(0LL, h[j] - B * m); | ~~~^~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/14/algorithm:60, from a.cc:1: /usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)' 257 | max(const _Tp& __a, const _Tp& __b) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed: a.cc:41:27: note: deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int64' {aka 'long int'}) 41 | int64 tt = max(0LL, h[j] - B * m); | ~~~^~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)' 303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate expects 3 arguments, 2 provided In file included from /usr/include/c++/14/algorithm:61: /usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)' 5706 | max(initializer_list<_Tp> __l) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate expects 1 argument, 2 provided /usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)' 5716 | max(initializer_list<_Tp> __l, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5716:5: note: template argument deduction/substitution failed: a.cc:41:27: note: mismatched types 'std::initializer_list<_Tp>' and 'long long int' 41 | int64 tt = max(0LL, h[j] - B * m); | ~~~^~~~~~~~~~~~~~~~~~~
s496189664
p03702
C++
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdint> #include <cstdio> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <tuple> #include <utility> #include <vector> using namespace std; using int64 = int64_t; int64 N, A, B; int64 h[100000]; int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N >> A >> B; for (int j = 0; j < N; ++j) { cin >> h[j]; } int64 l = 0, r = 1000000001; while (l < r) { int64 m = (l + r) / 2; int64 D = A-B, b = 0; for (int j = 0; j < N; ++j) { int64 tt = max(0LL, h[j] - B * m); b += (tt + D - 1) / D; } if (b <= m) { r = m; } else { l = m+1; } } cout << r << endl; return 0; }
a.cc: In function 'int main()': a.cc:41:27: error: no matching function for call to 'max(long long int, int64)' 41 | int64 tt = max(0LL, h[j] - B * m); | ~~~^~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/14/algorithm:60, from a.cc:1: /usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)' 257 | max(const _Tp& __a, const _Tp& __b) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed: a.cc:41:27: note: deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int64' {aka 'long int'}) 41 | int64 tt = max(0LL, h[j] - B * m); | ~~~^~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)' 303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate expects 3 arguments, 2 provided In file included from /usr/include/c++/14/algorithm:61: /usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)' 5706 | max(initializer_list<_Tp> __l) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate expects 1 argument, 2 provided /usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)' 5716 | max(initializer_list<_Tp> __l, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5716:5: note: template argument deduction/substitution failed: a.cc:41:27: note: mismatched types 'std::initializer_list<_Tp>' and 'long long int' 41 | int64 tt = max(0LL, h[j] - B * m); | ~~~^~~~~~~~~~~~~~~~~~~
s733344605
p03702
C
#include <iostream> #include <cstdio> #include <vector> #include <cmath> #include <cstring> #include <numeric> #include <algorithm> #include <functional> #include <array> #include <map> #include <queue> #include <limits.h> #include <set> #include <stack> #include <random> #include <complex> #include <unordered_map> #include <nmmintrin.h> #include <chrono> #define rep(i,s,n) for(int i = (s); (n) > i; i++) #define REP(i,n) rep(i,0,n) #define RANGE(x,a,b) ((a) <= (x) && (x) <= (b)) #define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b)) #define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d)) #define PW(x) ((x)*(x)) #define ALL(x) (x).begin(), (x).end() #define MODU 1000000007 #define bitcheck(a,b) ((a >> b) & 1) #define bitset(a,b) ( a |= (1 << b)) #define bitunset(a,b) (a &= ~(1 << b)) #define MP(a,b) make_pair((a),(b)) #define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second)) #define pritnf printf #define scnaf scanf #define itn int #ifdef _MSC_VER #define __builtin_popcount _mm_popcnt_u32 #define __builtin_popcountll _mm_popcnt_u64 #endif using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a%b); } template<typename A, size_t N, typename T> void Fill(A(&array)[N], const T &val) { std::fill((T*)array, (T*)(array + N), val); } signed main() { ll n,a,b; scanf("%lld %lld %lld", &n, &a, &b); vector<ll> p(n); REP(i, n) { scnaf("%lld", &p[i]); } sort(ALL(p)); ll sa = a - b; ll l = 0, r = p[n-1]/b+1; while (1) { ll mid = (l + r) / 2; ll cou = 0; REP(i, n) { ll cur = p[i] - b * mid; cou += (cur + sa-1)/sa; } if (cou > mid) { l = mid; } else r = mid; if (r - l <= 1) { printf("%lld\n", r); break; } } return 0; }
main.c:1:10: fatal error: iostream: No such file or directory 1 | #include <iostream> | ^~~~~~~~~~ compilation terminated.
s741594441
p03702
C++
v
a.cc:1:1: error: 'v' does not name a type 1 | v | ^
s869329257
p03702
C++
#include<iostream> #include<cstdio> #include<string> #include<algorithm> #include<map> #include<set> #include<vector> #include<unordered_map> #include<unordered_set> #include<list> #include<queue> #include<stack> #include<string.h> #include<functional> #include<limits.h> #define int long long using namespace std; int a[100000]; signed main() { int b, c, d; cin >> b >> c >> d; for (int e = 0; e < b; e++) { scanf("%lld", &a[e]); } int S = 0, G = pow(10, 15);//[S,G) while (G - S > 1) { int K = (S + G) / 2; int sum = 0; for (int i = 0; i < 100000; i++) { int T = max(a[i] - K*d, 0ll); sum += T / (c - d); if (T % (c - d))sum++; } if (sum <= K) { G = K; } else { S = K; } } cout << G << endl; }
a.cc: In function 'int main()': a.cc:25:24: error: 'pow' was not declared in this scope 25 | int S = 0, G = pow(10, 15);//[S,G) | ^~~
s691939199
p03703
Java
// copied #include <algorithm> #include <iostream> #include <vector> #include <cstdio> #include <map> using namespace std; typedef long long LL; const int maxn = 2e5 + 100; int n, k; LL a[maxn], c[maxn*4]; map<LL, int> M; vector<LL> V; void Modify(int x, int s){ for(; x <= n; x += x&(-x)) c[x] += s; } LL Query(int y){ if(y <= 0) return 0; LL ans = 0; for(int x = y; x; x -= x&(-x)) ans += c[x]; return ans; } int main() { int x; scanf("%d %d", &n, &k); for(int i = 1; i <= n; i++) scanf("%d", &x), a[i] = x; LL sum = 0; for(int i = 1; i <= n; i++) { sum += a[i]; sum -= k; V.push_back(sum); } sort(V.begin(), V.end()); for(int i = 0; i < V.size(); i++) M[V[i]] = i+1; sum = 0; LL ans = 0; for(int i = 1; i <= n; i++){ sum += a[i]; sum -= k; ans += Query(M[sum]); if(sum >= 0) ans++; Modify(M[sum], 1); } cout<<ans<<endl; }
Main.java:2: error: illegal character: '#' #include <algorithm> ^ Main.java:3: error: illegal character: '#' #include <iostream> ^ Main.java:4: error: illegal character: '#' #include <vector> ^ Main.java:5: error: illegal character: '#' #include <cstdio> ^ Main.java:6: error: illegal character: '#' #include <map> ^ Main.java:8: error: class, interface, enum, or record expected typedef long long LL; ^ Main.java:9: error: class, interface, enum, or record expected const int maxn = 2e5 + 100; ^ Main.java:10: error: class, interface, enum, or record expected int n, k; ^ Main.java:11: error: class, interface, enum, or record expected LL a[maxn], c[maxn*4]; ^ Main.java:12: error: unnamed classes are a preview feature and are disabled by default. map<LL, int> M; ^ (use --enable-preview to enable unnamed classes) Main.java:46: error: not a statement cout<<ans<<endl; ^ Main.java:27: error: illegal start of expression scanf("%d %d", &n, &k); ^ Main.java:27: error: illegal start of expression scanf("%d %d", &n, &k); ^ Main.java:28: error: illegal start of expression for(int i = 1; i <= n; i++) scanf("%d", &x), a[i] = x; ^ Main.java:28: error: ';' expected for(int i = 1; i <= n; i++) scanf("%d", &x), a[i] = x; ^ 15 errors
s658875859
p03703
C++
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <bits/stdc++.h> using namespace __gnu_pbds; using namespace std; typedef tree< pair<ll,int>, null_type, less<pair<ll,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define F0R(i,a) FOR(i,0,a) #define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i) #define R0F(i,a) ROF(i,0,a) #define f first #define s second using ll = long long; using ld = long double; ll INF = LLONG_MAX; using vi = vector<int>; using vll = vector<ll>; using pii = pair<int, int>; namespace output { void pr(int x) { cout << x; } void pr(long x) { cout << x; } void pr(ll x) { cout << x; } void pr(unsigned x) { cout << x; } void pr(unsigned long x) { cout << x; } void pr(unsigned long long x) { cout << x; } void pr(float x) { cout << x; } void pr(double x) { cout << x; } void pr(ld x) { cout << x; } void pr(char x) { cout << x; } void pr(const char* x) { cout << x; } void pr(const string& x) { cout << x; } void pr(bool x) { pr(x ? "true" : "false"); } template<class T> void pr(const complex<T>& x) { cout << x; } template<class T1, class T2> void pr(const pair<T1,T2>& x); template<class T> void pr(const T& x); template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { pr(t); pr(ts...); } template<class T1, class T2> void pr(const pair<T1,T2>& x) { pr("{",x.f,", ",x.s,"}"); } template<class T> void pr(const T& x) { pr("{"); // const iterator needed for vector<bool> bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; pr("}"); } void print() { pr("\n"); } // print w/ spaces template<class T, class... Ts> void print(const T& t, const Ts&... ts) { pr(t); if (sizeof...(ts)) pr(" "); print(ts...); } } using namespace output; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); ordered_set seenPrefs; int N, K; cin >> N >> K; vi arr (N); F0R(i, N) { cin >> arr[i]; arr[i] -= K; } ll ans = 0; ll curPref = 0; F0R(i, N) { seenPrefs.insert({curPref, i}); curPref += arr[i]; auto above = seenPrefs.upper_bound({curPref, N}); if (above == seenPrefs.begin()) continue; --above; ans += seenPrefs.order_of_key(*above) + 1; } print(ans); }
a.cc:11:8: error: 'll' was not declared in this scope 11 | pair<ll,int>, | ^~ a.cc:11:14: error: template argument 1 is invalid 11 | pair<ll,int>, | ^ a.cc:13:13: error: 'll' was not declared in this scope 13 | less<pair<ll,int>>, | ^~ a.cc:13:16: error: template argument 1 is invalid 13 | less<pair<ll,int>>, | ^~~ a.cc:13:19: error: template argument 1 is invalid 13 | less<pair<ll,int>>, | ^~ a.cc:15:36: error: template argument 1 is invalid 15 | tree_order_statistics_node_update> | ^ a.cc:15:36: error: template argument 3 is invalid a.cc: In function 'int main()': a.cc:88:27: error: request for member 'insert' in 'seenPrefs', which is of non-class type 'ordered_set' {aka 'int'} 88 | seenPrefs.insert({curPref, i}); | ^~~~~~ a.cc:90:40: error: request for member 'upper_bound' in 'seenPrefs', which is of non-class type 'ordered_set' {aka 'int'} 90 | auto above = seenPrefs.upper_bound({curPref, N}); | ^~~~~~~~~~~ a.cc:91:40: error: request for member 'begin' in 'seenPrefs', which is of non-class type 'ordered_set' {aka 'int'} 91 | if (above == seenPrefs.begin()) continue; | ^~~~~ a.cc:93:34: error: request for member 'order_of_key' in 'seenPrefs', which is of non-class type 'ordered_set' {aka 'int'} 93 | ans += seenPrefs.order_of_key(*above) + 1; | ^~~~~~~~~~~~
s198002561
p03703
C++
//#pragma GCC target("avx2") //#pragma GCC optimize("O3") //#include <x86intrin.h> #include <algorithm> #include <iostream> #include <cstring> #include <string> #include <bitset> #include <vector> #include <cmath> #include <deque> #include <queue> #include <iomanip> #include <stack> #include <map> #include <set> //#include <ordered_set> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> //using namespace __gnu_pbds; using namespace std; //template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define F first #define S second #define lb lower_bound #define ub upper_bound #define pb push_back #define pf push_front #define ppb pop_back #define mp make_pair #define bpp __builtin_popcountll #define sqr(x) ((x) * (x)) #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define in insert #define ppf pop_front #define endl '\n' //#define int long long typedef unsigned long long ull; typedef long long ll; typedef long double ld; typedef pair <int, int> pii; const int mod = (int)1e9 + 7; const int N = (int)3e5 + 123; const ll inf = (ll)1e18 + 1; const double pi = acos (-1.0); const double eps = 1e-9; const int dx[] = {0, 0, 1, 0, -1}; const int dy[] = {0, 1, 0, -1, 0}; int n, a[N]; ll pref[N], k, ans; ordered_set < pair <ll, int> > s; inline void boost () { ios_base :: sync_with_stdio (0); cin.tie (0), cout.tie (0); } inline void Solve () { cin >> n >> k; for (int i = 1; i <= n; i ++) { cin >> a[i]; pref[i] = pref[i - 1] + a[i]; } for (int i = 1; i <= n; i ++) { s.in ({pref[i - 1] - k * (i - 1), i - 1}); ans += s.order_of_key ({pref[i] - 1ll * k * i, mod}); } cout << ans; //(pref[r] - pref[l - 1]) / (r - l + 1) >= k //pref[r] - pref[l - 1] >= k * (r - (l - 1)) //pref[r] - pref[l - 1] >= k * r - k * (l - 1) //pref[r] - k * r >= pref[l - 1] - k * (l - 1) } signed main () { // #ifdef QWERTY // freopen("input", "r", stdin); // #endif // freopen (".in", "r", stdin); // freopen (".out", "w", stdout); boost (); int tt = 1; //cin >> tt; while (tt --) { Solve (); } return 0; }
a.cc:60:1: error: 'ordered_set' does not name a type 60 | ordered_set < pair <ll, int> > s; | ^~~~~~~~~~~ a.cc: In function 'void Solve()': a.cc:74:7: error: 's' was not declared in this scope 74 | s.in ({pref[i - 1] - k * (i - 1), i - 1}); | ^
s165633146
p03703
C++
k
a.cc:1:1: error: 'k' does not name a type 1 | k | ^
s715255526
p03703
C++
/// IN THE NAME OF METAL #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> pll; #define sz(x) (ll) x.size() #define all(x) (x).begin(),(x).end() #define F first #define S second ll Pow(ll a, ll b, ll md, ll ans = 1) { for (; b; b >>= 1, a = a * a % md) if (b & 1) ans = ans * a % md; return ans % md; } const ll MAXN = 1e6 + 10; const ll INF = 818; const ll MOD = 1e9 + 7; ll ind[MAXN], fen[MAXN], A[MAXN], ps[MAXN], ans = 0, n, P; vector<ll> compress; void update(ll ind, ll val) { for (; ind < MAXN; ind += ind & -ind) fen[ind] += val; } ll get(ll ind, ll res = 0) { for (; ind; ind -= ind & -ind) res += fen[ind]; return res; } int main() { scanf("%lld%lld", &n, &p); for (ll i = 1; i <= n; i++) { scanf("%lld", &A[i]); } for (ll i = 1; i <= n; i++) { A[i] -= P; } partial_sum(A, A + MAXN, ps); for (ll i = 0; i <= n; i++) { compress.push_back(ps[i]); } sort(all(compress)); compress.resize(unique(all(compress)) - compress.begin()); for (ll i = 0; i <= n; i++) { ind[i] = lower_bound(all(compress), ps[i]) - compress.begin() + 1; ans += get(ind[i]); update(ind[i], 1); } printf("%lld", ans); return 0; }
a.cc: In function 'int main()': a.cc:37:28: error: 'p' was not declared in this scope 37 | scanf("%lld%lld", &n, &p); | ^
s353870185
p03703
C++
#include <bits/stdc++.h> using namespace std; using llong = long long int; #define rep(i, n) for (int i = 0; i < (n); ++i) #define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr) #define all(x) x.begin(), x.end() #define allr(x) x.rbegin(), x.rend() const int MOD = 1000000007; const int INF = 1000000000; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; const int MAX = 200101; long long fac[MAX], finv[MAX], inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++){ fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } long long COM(int n, int k){ if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } ////////////////////////////////////////////////////////////////////////////////// int main (int argc, char *argv[]) { cin.tie(0); ios::sync_with_stdio(false); // for file input /* ifstream in("input.txt"); ifstream in("input.txt"); */ int n; cin >> n; llong k; cin >> k; vector<llong> A(n); rep(i, n) cin >> A[i]; vector<llong> cumA(n + 1); cumA[0] = 0; rep(i, n) cumA[i + 1] = cumA[i] + A[i]; vector<llong> B(n); rep(i, n) B[i] = cumA[i + 1] * A[i]; vector<llong> compresed; rep(i, n) compresed.emplace_back(B[i]); sort(all(compresed)); compresed.erase(unique(all(compresed)), compresed.end); llong ans = 0; rep(i, n) { int index = lower_bound(all(compresed), B[i]) - compresed.begin(); } return 0; } //////////////////////////////////////////////////////////////////////////////////
a.cc: In function 'int main(int, char**)': a.cc:60:20: error: no matching function for call to 'std::vector<long long int>::erase(__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >, <unresolved overloaded function type>)' 60 | compresed.erase(unique(all(compresed)), compresed.end); | ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/14/vector:66, from /usr/include/c++/14/functional:64, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53, from a.cc:1: /usr/include/c++/14/bits/stl_vector.h:1536:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(const_iterator) [with _Tp = long long int; _Alloc = std::allocator<long long int>; iterator = std::vector<long long int>::iterator; const_iterator = std::vector<long long int>::const_iterator]' 1536 | erase(const_iterator __position) | ^~~~~ /usr/include/c++/14/bits/stl_vector.h:1536:7: note: candidate expects 1 argument, 2 provided /usr/include/c++/14/bits/stl_vector.h:1564:7: note: candidate: 'std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::erase(const_iterator, const_iterator) [with _Tp = long long int; _Alloc = std::allocator<long long int>; iterator = std::vector<long long int>::iterator; const_iterator = std::vector<long long int>::const_iterator]' 1564 | erase(const_iterator __first, const_iterator __last) | ^~~~~ /usr/include/c++/14/bits/stl_vector.h:1564:52: note: no known conversion for argument 2 from '<unresolved overloaded function type>' to 'std::vector<long long int>::const_iterator' 1564 | erase(const_iterator __first, const_iterator __last) | ~~~~~~~~~~~~~~~^~~~~~
s953714426
p03703
C++
#include <iterator> #include <numeric> #include <vector> using namespace std; int main(int argc, const char *argv[]) { using ll = long long; int n; ll k; cin >> n >> k; vector<ll> va(n); for (auto &a : va) { cin >> a; } ll ans = 0; vector<ll> csum{0}; partial_sum(va.begin(), va.end(), back_inserter(csum)); for (int i = 0; i < va.size(); i++) { bool l_found = false; for (int j = 1; j <= va.size() - i; j++) { // iからj個とる ll lower = k * j + csum[i]; if (lower <= csum[i + j]) { l_found = true; ans++; } else if (l_found) { break; } } } cout << ans << '\n'; return 0; }
a.cc: In function 'int main(int, const char**)': a.cc:11:3: error: 'cin' was not declared in this scope 11 | cin >> n >> k; | ^~~ a.cc:4:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>' 3 | #include <vector> +++ |+#include <iostream> 4 | a.cc:34:3: error: 'cout' was not declared in this scope 34 | cout << ans << '\n'; | ^~~~ a.cc:34:3: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
s189847117
p03703
C++
#define ASIZE 200005 #include <bits/stdc++.h> using namespace std; long long ft[ASIZE],n=ASIZE+1; typedef pair<long long,long long> pii; void increment(long long p){ for(;p<=n;p+=(p & -p))ft[p]++; } long long query(long long p){ long long sum=0; for(;p>0;p-=(p & -p))sum+=ft[p]; return sum; } long long main() { long long n,k,a[ASIZE]={0},ps[ASIZE],x,sum=0; priority_queue<pii,vector<pii>,greater<pii> >pq; cin>>n>>k; for(long long i=1;i<=n;i++){ cin>>a[i]; a[i]-=k; ps[i]=ps[i-1]+a[i]; pq.emplace(ps[i],i); } while(!pq.empty()){ x=pq.top().second; // cout<<"x= "<<x<<"\n"; sum+=query(x); increment(x); if(pq.top().first>=0)sum++; pq.pop(); } cout<<sum; return 0; }
cc1plus: error: '::main' must return 'int'
s759430621
p03703
C++
#ifdef LOCAL #pragma GCC optimize ("O0") #else #pragma GCC optimize ("O3") #pragma GCC optimize ("unroll-loops") #pragma GCC target ("avx") #endif #include <vector> #include <set> #include <map> #include <tuple> #include <queue> #include <stack> #include <bitset> #include <functional> #include <algorithm> #include <utility> #include <numeric> #include <iostream> #include <cmath> using namespace std; using ll = long long; using VI = vector<int>; using VVI = vector<vector<int>>; using VLL = vector<ll>; using VVLL = vector<vector<ll>>; using VB = vector<bool>; using VVB = vector<vector<bool>>; using PII = pair<int, int>; template <typename T> using minheap = priority_queue<T, vector<T>, greater<T>>; const int INF = 1e9 + 7; const ll INF_LL = (ll)1e18 + 7; #define __overload3(_1, _2, _3, name,...) name #define rep(...) __overload3(__VA_ARGS__, repFromUntil, repUntil, repeat)(__VA_ARGS__) #define repeat(times) repFromUntil(__name##__LINE__, 0, times) #define repUntil(name, times) repFromUntil(name, 0, times) #define repFromUntil(name, from, until) for (int name = from, name##__until = (until); name < name##__until; name++) #define repr(...) __overload3(__VA_ARGS__, reprFromUntil, reprUntil, repeat)(__VA_ARGS__) #define reprUntil(name, times) reprFromUntil(name, 0, times) #define reprFromUntil(name, from, until) for (int name = until - 1, name##__from = (from); name >= name##__from; name--) #define EXIT(out) do { OUT(out); exit(0); } while (0) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) #define _1 first #define _2 second #define debug(v) do {debugos << "L" << __LINE__ << " " << #v << " > ";debugos<<(v)<<newl;} while (0) #define debugv(v) do {debugos << "L" << __LINE__ << " " << #v << " > ";for(auto e:(v)){debugos<<e<<" ";}debugos<<newl;} while (0) #define debuga(m,w) do {debugos << "L" << __LINE__ << " " << #m << " > ";for(int x=0;x<(w);x++){debugos<<(m)[x]<<" ";}debugos<<newl;} while (0) #define debugaa(m,h,w) do {debugos << "L" << __LINE__ << " " << #m << " > \n";for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){debugos<<(m)[y][x]<<" ";}debugos<<newl;}} while (0) #define newl "\n" constexpr int dr[] = {1,-1,0,0}; // LRUD constexpr int dc[] = {0,0,1,-1}; bool inside(int r, int c, int H, int W) { return 0 <= r and r < H and 0 <= c and c < W; } template <typename T> bool chmin(T& var, T x) { if (var > x) { var = x; return true; } else return false; } template <typename T> bool chmax(T& var, T x) { if (var < x) { var = x; return true; } else return false; } template <typename T> struct minT { T operator()(T a, T b) { return min(a, b); } }; template <typename T> struct maxT { T operator()(T a, T b) { return max(a, b); } }; template <typename T> int sgn(T val) { return (T(0) < val) - (val < T(0)); } ll power(ll e, int t, ll mod = INF_LL) { ll res = 1; while (t) { if (t&1) res = (res * e) % mod; t >>= 1; e = (e * e) % mod; } return res; } template <typename T> T divceil(T, T); template <typename T> T divfloor(T m, T d) { if (sgn(m) * sgn(d) >= 0) return m / d; else return -divceil(abs(m), abs(d)); } template <typename T> T divceil(T m, T d) { if (m >= 0 and d > 0) return (m+d-1)/d; else if (m < 0 and d < 0) return divceil(-m, -d); else return -divfloor(abs(m), abs(d)); } template<typename T> vector<T> make_v(size_t a, T b){return vector<T>(a, b);} template<typename... Ts> auto make_v(size_t a, Ts... ts){ return vector<decltype(make_v(ts...))>(a, make_v(ts...)); } string operator*(const string& s, int times) { string res = ""; rep(times) res += s; return res; } class MyScanner { public: int offset = 0; template <typename T> void input_integer(T& var) { var = 0; T sign = 1; int cc = getchar(); for (; cc<'0' || '9'<cc; cc = getchar()) if (cc == '-') sign = -1; for (; '0' <= cc && cc <= '9'; cc = getchar()) var = (var << 3) + (var << 1) + cc - '0'; var = var * sign; var += offset; } int c() { char c; while (c = getchar(), c == ' ' or c == '\n'); return c; } MyScanner& operator>>(char& var) { var = c(); return *this; } MyScanner& operator>>(int& var) { input_integer<int>(var); return *this; } MyScanner& operator>>(ll& var) { input_integer<ll>(var); return *this; } MyScanner& operator>>(string& var) { var = ""; int cc = getchar(); for (; !isvisiblechar(cc); cc = getchar()); for (; isvisiblechar(cc); cc = getchar()) var.push_back(cc); return *this; } template <typename T> operator T() { T x; *this >> x; return x; } template <typename T> void operator()(T &t) { *this >> t; } template <typename T, typename... Ts> void operator()(T &t, Ts &...ts) { *this >> t; this->operator()(ts...); } template <typename Iter> void iter(Iter first, Iter last) { while (first != last) *this >> *first, first++; } VI vi(int n) { VI res(n); iter(all(res)); return res; } VVI vvi(int n, int m) { VVI res(n); rep(i, n) res[i] = vi(m); return res; } VLL vll(int n) { VLL res(n); iter(all(res)); return res; } VVLL vvll(int n, int m) { VVLL res(n); rep(i, n) res[i] = vll(m); return res; } template <typename T> vector<T> v(int n) { vector<T> res(n); iter(all(res)); return res; } private: int isvisiblechar(int c) { return 0x21 <= c && c <= 0x7E; } } IN, IN1{-1}; class MyPrinter { public: template <typename T> void output_integer(T var) { if (var == 0) { putchar('0'); return; } if (var < 0) putchar('-'), var = -var; char stack[32]; int stack_p = 0; while (var) stack[stack_p++] = '0' + (var % 10), var /= 10; while (stack_p) putchar(stack[--stack_p]); } MyPrinter& operator<<(char c) { putchar(c); return *this; } MyPrinter& operator<<(double x) { printf("%.10f\n", x); return *this; } template <typename T> MyPrinter& operator<<(T var) { output_integer<T>(var); return *this; } MyPrinter& operator<<(char* str_p) { while (*str_p) putchar(*(str_p++)); return *this; } MyPrinter& operator<<(const char* str_p) { while (*str_p) putchar(*(str_p++)); return *this; } MyPrinter& operator<<(const string& str) { const char* p = str.c_str(); const char* l = p + str.size(); while (p < l) putchar(*p++); return *this; } template <typename T> void operator()(T x) { *this << x << newl; } template <typename T, typename... Ts> void operator()(T x, Ts ...xs) { *this << x << " "; this->operator()(xs...); } template <typename Iter> void iter(Iter s, Iter t) { if (s == t) *this << "\n"; else { for (; s != t; s++) { *this << *s << " \n"[next(s, 1) == t]; } } } template <typename Range> void range(const Range& r) { iter(begin(r), end(r)); } } OUT; class DebugPrint { public: template <typename T> DebugPrint& operator <<(const T& v) { #ifdef LOCAL cerr << v; #endif return *this; } } debugos; struct BIT { const int n; vector<ll> data; BIT(int n = 0): n(n), data(n+1) { } void add(int p, ll v) { p++; while (p <= n) { data[p] += v; p += p & -p; } } // sum over [0, p) ll sum(int p) { ll res = 0; while (p) { res += data[p]; p -= p & -p; } return res; } // sum over [l, r) ll sum(int l, int r) { return sum(r) - sum(l); } }; template <typename T, typename U> ostream& operator<<(ostream& out, pair<T, U> var) { return out << var.first << " " << var.second; } template <typename Tuple, size_t I, size_t N, enable_if_t<I == N>* = nullptr> ostream& tuple_impl(ostream& out, Tuple var) { return out; } template <typename Tuple, size_t I, size_t N, enable_if_t<I != N>* = nullptr> ostream& tuple_impl(ostream& out, Tuple var) { out << get<I>(var) << " "; return tuple_impl<Tuple, I+1, N>(out, var); } template <typename... Ts> ostream& operator<<(ostream& out, tuple<Ts...> var) { return tuple_impl<tuple<Ts...>, 0, sizeof...(Ts)>(out, var); } template <typename T, typename U> MyPrinter& operator<<(MyPrinter& out, pair<T, U> var) { return out << var.first << " " << var.second; } template <typename Tuple, size_t I, size_t N, enable_if_t<I == N>* = nullptr> MyPrinter& tuple_impl(MyPrinter& out, Tuple var) { return out; } template <typename Tuple, size_t I, size_t N, enable_if_t<I != N>* = nullptr> MyPrinter& tuple_impl(MyPrinter& out, Tuple var) { out << get<I>(var) << " "; return tuple_impl<Tuple, I+1, N>(out, var); } template <typename... Ts> MyPrinter& operator<<(MyPrinter& out, tuple<Ts...> var) { return tuple_impl<tuple<Ts...>, 0, sizeof...(Ts)>(out, var); } template <typename T, typename U> MyScanner& operator>>(MyScanner& in, pair<T, U>& var) { return in >> var.first >> var.second; } template <typename... Ts> MyScanner& operator>>(MyScanner& in, tuple<Ts...>& var) { return tuple_impl<tuple<Ts...>, 0, sizeof...(Ts)>(in, var); } template <typename Tuple, size_t I, size_t N, enable_if_t<I == N>* = nullptr> MyScanner& tuple_impl(MyScanner& in, Tuple& var) { return in; } template <typename Tuple, size_t I, size_t N, enable_if_t<I != N>* = nullptr> MyScanner& tuple_impl(MyScanner& in, Tuple& var) { in >> get<I>(var); return tuple_impl<Tuple, I+1, N>(in, var); } int main() { ll n = IN, k = IN; auto a = IN.vll(n); VLL acc(a.size()+1); rep(i, a.size()) acc[i+1] = acc[i] + a[i]; map<ll, int> zarts; rep(i, n+1) zarts[acc[i]-k*i] = 0; int t = 0; for (auto& [k, v] : zarts) v = t++; BIT bit(t); ll res = 0; debugv(zarts); rep(i, n+1) { int zt = zarts[acc[i]-k*i]; res += bit.sum(zt+1); bit.add(zt, 1); } OUT(res); }
In file included from /usr/include/c++/14/vector:63, from a.cc:9: /usr/include/c++/14/bits/allocator.h: In destructor 'std::__cxx11::basic_string<char>::_Alloc_hider::~_Alloc_hider()': /usr/include/c++/14/bits/allocator.h:182:7: error: inlining failed in call to 'always_inline' 'std::allocator< <template-parameter-1-1> >::~allocator() noexcept [with _Tp = char]': target specific option mismatch 182 | ~allocator() _GLIBCXX_NOTHROW { } | ^ In file included from /usr/include/c++/14/string:54, from /usr/include/c++/14/bitset:52, from a.cc:15: /usr/include/c++/14/bits/basic_string.h:186:14: note: called from here 186 | struct _Alloc_hider : allocator_type // TODO check __is_final | ^~~~~~~~~~~~
s695401729
p03703
Java
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; import java.util.function.IntUnaryOperator; import java.util.function.LongUnaryOperator; import static com.yu212.Utils.println; class Main { static In in = new In(); static Out out = new Out(); static long mod = 1000000007; static long inf = 0xfffffffffffffffL; void solve() { int n = in.nextInt(); long k = in.nextLong(); long[] a = in.nextLongArray(n); long[] s = new long[n + 1]; List<Pair<Long, Integer>> list = new ArrayList<>(); list.add(new Pair<>(0L, 0)); for (int i = 1; i <= n; i++) { s[i] = s[i - 1] + a[i - 1] - k; list.add(new Pair<>(s[i], i)); } Comparator<Pair<Long, Integer>> comparator = Comparator.comparing((Pair<Long, Integer> pair) -> pair.first).thenComparing(pair -> pair.second); list.sort(comparator); SegmentTree segmentTree = new SegmentTree(n); long ans = 0; for (Pair<Long, Integer> pair : list) { println(pair, segmentTree.get(pair.second)); ans += segmentTree.get(pair.second); segmentTree.addValue(pair.second, n + 1, 1); } out.println(ans); } static class Pair<F, S> { F first; S second; Pair(F first, S second) { this.first = first; this.second = second; } @Override public String toString() { return String.format("{%s, %s}", first, second); } } public static void main(String[]$) { new Main().solve(); out.flush(); } } class SegmentTree { private int n; private long[] min; private long[] secondMin; private long[] minCount; private long[] max; private long[] secondMax; private long[] maxCount; private long[] sum; private long[] len; private long[] ladd; private long[] lvalue; SegmentTree(int n) { this(n, null); } SegmentTree(long[] a) { this(a.length, a); } private SegmentTree(int m, long[] a) { this.n = m == 1 ? 1 : Integer.highestOneBit(m - 1) << 1; this.min = new long[n * 2]; this.secondMin = new long[n * 2]; this.minCount = new long[n * 2]; this.max = new long[n * 2]; this.secondMax = new long[n * 2]; this.maxCount = new long[n * 2]; this.sum = new long[n * 2]; this.len = new long[n * 2]; this.ladd = new long[n * 2]; this.lvalue = new long[n * 2]; for (int i = 0; i < n * 2; i++) { ladd[i] = 0; lvalue[i] = Main.inf; } len[0] = n; for (int i = 0; i < n - 1; i++) { len[i * 2 + 1] = len[i * 2 + 2] = len[i] >> 1; } for (int i = 0; i < n; i++) { if (i < m) { max[n - 1 + i] = min[n - 1 + i] = sum[n - 1 + i] = a == null ? 0 : a[i]; secondMax[n - 1 + i] = -Main.inf; secondMin[n - 1 + i] = Main.inf; maxCount[n - 1 + i] = minCount[n - 1 + i] = 1; } else { max[n - 1 + i] = secondMax[n - 1 + i] = -Main.inf; min[n - 1 + i] = secondMin[n - 1 + i] = Main.inf; maxCount[n - 1 + i] = minCount[n - 1 + i] = 0; } } for (int i = n - 2; i >= 0; i--) { update(i); } } void changeMin(int i, long x) { updateMin(x, i, i + 1, 0, 0, n); } void changeMax(int i, long x) { updateMax(x, i, i + 1, 0, 0, n); } void addValue(int i, long x) { addValue(x, i, i + 1, 0, 0, n); } void setValue(int i, long x) { updateValue(x, i, i + 1, 0, 0, n); } long getMin(int i) { return getMin(i, i + 1, 0, 0, n); } long getMax(int i) { return getMax(i, i + 1, 0, 0, n); } long get(int i) { return getSum(i, i + 1, 0, 0, n); } void changeMin(int l, int r, long x) { updateMin(x, l, r, 0, 0, n); } void changeMax(int l, int r, long x) { updateMax(x, l, r, 0, 0, n); } void addValue(int l, int r, long x) { addValue(x, l, r, 0, 0, n); } void setValue(int l, int r, long x) { updateValue(x, l, r, 0, 0, n); } long getMin(int l, int r) { return getMin(l, r, 0, 0, n); } long getMax(int l, int r) { return getMax(l, r, 0, 0, n); } long getSum(int l, int r) { return getSum(l, r, 0, 0, n); } private void updateNodeMin(int k, long x) { sum[k] += (x - min[k]) * minCount[k]; if (min[k] == max[k]) { min[k] = max[k] = x; } else if (min[k] == secondMax[k]) { min[k] = secondMax[k] = x; } else { min[k] = x; } if (lvalue[k] != Main.inf && lvalue[k] < x) { lvalue[k] = x; } } private void updateNodeMax(int k, long x) { sum[k] += (x - max[k]) * maxCount[k]; if (max[k] == min[k]) { max[k] = min[k] = x; } else if (max[k] == secondMin[k]) { max[k] = secondMin[k] = x; } else { max[k] = x; } if (lvalue[k] != Main.inf && x < lvalue[k]) { lvalue[k] = x; } } private void push(int k) { if (k < n - 1) { if (lvalue[k] != Main.inf) { updateAll(k * 2 + 1, lvalue[k]); updateAll(k * 2 + 2, lvalue[k]); lvalue[k] = Main.inf; } else { if (ladd[k] != 0) { addAll(k * 2 + 1, ladd[k]); addAll(k * 2 + 2, ladd[k]); ladd[k] = 0; } if (max[k] < max[k * 2 + 1]) { updateNodeMax(k * 2 + 1, max[k]); } if (min[k * 2 + 1] < min[k]) { updateNodeMin(k * 2 + 1, min[k]); } if (max[k] < max[k * 2 + 2]) { updateNodeMax(k * 2 + 2, max[k]); } if (min[k * 2 + 2] < min[k]) { updateNodeMin(k * 2 + 2, min[k]); } } } } private void update(int k) { sum[k] = sum[k * 2 + 1] + sum[k * 2 + 2]; if (max[k * 2 + 1] < max[k * 2 + 2]) { max[k] = max[k * 2 + 2]; maxCount[k] = maxCount[k * 2 + 2]; secondMax[k] = Math.max(max[k * 2 + 1], secondMax[k * 2 + 2]); } else if (max[k * 2 + 2] < max[k * 2 + 1]) { max[k] = max[k * 2 + 1]; maxCount[k] = maxCount[k * 2 + 1]; secondMax[k] = Math.max(secondMax[k * 2 + 1], max[k * 2 + 2]); } else { max[k] = max[k * 2 + 1]; maxCount[k] = maxCount[k * 2 + 1] + maxCount[k * 2 + 2]; secondMax[k] = Math.max(secondMax[k * 2 + 1], secondMax[k * 2 + 2]); } if (min[k * 2 + 1] < min[k * 2 + 2]) { min[k] = min[k * 2 + 1]; minCount[k] = minCount[k * 2 + 1]; secondMin[k] = Math.min(secondMax[k * 2 + 1], min[k * 2 + 2]); } else if (min[k * 2 + 2] < min[k * 2 + 1]) { min[k] = min[k * 2 + 2]; minCount[k] = minCount[k * 2 + 2]; secondMax[k] = Math.min(min[k * 2 + 1], secondMin[k * 2 + 2]); } else { min[k] = min[k * 2 + 1]; minCount[k] = minCount[k * 2 + 1] + minCount[k * 2 + 2]; secondMin[k] = Math.min(secondMin[k * 2 + 1], secondMin[k * 2 + 2]); } } private void updateMin(long x, int a, int b, int k, int l, int r) { if (l < b && a < r && x < max[k]) { if (a <= l && r <= b && secondMax[k] < x) { updateNodeMax(k, x); } else { push(k); updateMin(x, a, b, k * 2 + 1, l, (l + r) / 2); updateMin(x, a, b, k * 2 + 2, (l + r) / 2, r); update(k); } } } private void updateMax(long x, int a, int b, int k, int l, int r) { if (l < b && a < r && min[k] < x) { if (a <= l && r <= b && x < secondMin[k]) { updateNodeMin(k, x); } else { push(k); updateMax(x, a, b, k * 2 + 1, l, (l + r) / 2); updateMax(x, a, b, k * 2 + 2, (l + r) / 2, r); update(k); } } } private void addAll(int k, long x) { max[k] += x; if (secondMax[k] != -Main.inf) { secondMax[k] += x; } min[k] += x; if (secondMin[k] != Main.inf) { secondMin[k] += x; } sum[k] += len[k] * x; if (lvalue[k] != Main.inf) { lvalue[k] += x; } else { ladd[k] += x; } } private void updateAll(int k, long x) { max[k] = x; secondMax[k] = -Main.inf; min[k] = x; secondMin[k] = Main.inf; maxCount[k] = minCount[k] = len[k]; sum[k] = x * len[k]; lvalue[k] = x; ladd[k] = 0; } private void addValue(long x, int a, int b, int k, int l, int r) { if (l < b && a < r) { if (a <= l && r <= b) { addAll(k, x); } else { push(k); addValue(x, a, b, k * 2 + 1, l, (l + r) / 2); addValue(x, a, b, k * 2 + 2, (l + r) / 2, r); update(k); } } } private void updateValue(long x, int a, int b, int k, int l, int r) { if (l < b && a < r) { if (a <= l && r <= b) { updateAll(k, x); } else { push(k); updateValue(x, a, b, k * 2 + 1, l, (l + r) / 2); updateValue(x, a, b, k * 2 + 2, (l + r) / 2, r); update(k); } } } private long getMin(int a, int b, int k, int l, int r) { if (b <= l || r <= a) { return Main.inf; } if (a <= l && r <= b) { return min[k]; } push(k); long lv = getMin(a, b, k * 2 + 1, l, (l + r) / 2); long rv = getMin(a, b, k * 2 + 2, (l + r) / 2, r); return Math.min(lv, rv); } private long getMax(int a, int b, int k, int l, int r) { if (b <= l || r <= a) { return -Main.inf; } if (a <= l && r <= b) { return max[k]; } push(k); long lv = getMax(a, b, k * 2 + 1, l, (l + r) / 2); long rv = getMax(a, b, k * 2 + 2, (l + r) / 2, r); return Math.max(lv, rv); } private long getSum(int a, int b, int k, int l, int r) { if (b <= l || r <= a) { return 0; } if (a <= l && r <= b) { return sum[k]; } push(k); long lv = getSum(a, b, k * 2 + 1, l, (l + r) / 2); long rv = getSum(a, b, k * 2 + 2, (l + r) / 2, r); return lv + rv; } } class In { private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 0x10000); private StringTokenizer tokenizer; String next() { try { while (tokenizer == null || !tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(reader.readLine()); } } catch (IOException ignored) { } return tokenizer.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } char[][] nextCharArray(int n, int m) { char[][] a = new char[n][m]; for (int i = 0; i < n; i++) { a[i] = next().toCharArray(); } return a; } int[] nextIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } int[] nextIntArray(int n, IntUnaryOperator op) { int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = op.applyAsInt(nextInt()); } return a; } long[] nextLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) { a[i] = nextLong(); } return a; } long[] nextLongArray(int n, LongUnaryOperator op) { long[] a = new long[n]; for (int i = 0; i < n; i++) { a[i] = op.applyAsLong(nextLong()); } return a; } } class Out { private PrintWriter out = new PrintWriter(System.out); boolean autoFlush = false; void println(Object... a) { StringJoiner joiner = new StringJoiner(" "); for (Object obj : a) { joiner.add(String.valueOf(obj)); } out.println(joiner); if (autoFlush) { out.flush(); } } void println(int[] a) { StringJoiner joiner = new StringJoiner(" "); for (int i : a) { joiner.add(Integer.toString(i)); } out.println(joiner); if (autoFlush) { out.flush(); } } void println(long[] a) { StringJoiner joiner = new StringJoiner(" "); for (long i : a) { joiner.add(Long.toString(i)); } out.println(joiner); if (autoFlush) { out.flush(); } } void flush() { out.flush(); } }
Main.java:9: error: package com.yu212 does not exist import static com.yu212.Utils.println; ^ Main.java:9: error: static import only from classes and interfaces import static com.yu212.Utils.println; ^ Main.java:33: error: cannot find symbol println(pair, segmentTree.get(pair.second)); ^ symbol: method println(Pair<Long,Integer>,long) location: class Main 3 errors
s951127536
p03703
C++
#include "bits/stdc++.h" #define ll long long #define fr first #define sc second using namespace std; const int mnx = 1e7 + 9; const int mod = 1e9 + 7; const double PI = acos(-1); ll n, k, a[mnx], t[mnx], h; pair <int, int> z[mnx]; get(int x){ ll res = 0; for(; x > 0; x -= (x & -x)){ res += t[x]; } return res; } upd(int x){ for(; x <= n; x += (x & -x)){ t[x]++; } } void solve(){ cin >> n >> k; for(int i = 1; i <= n; i++){ cin >> a[i]; a[i] -= k; } ll sum = 0; for(int i = 1; i <= n; i++){ sum += a[i]; z[i] = {sum, i}; } sort (z + 1, z + n + 1); ll ans = 0; for(int i = 1; i <= n; i++){ upd(z[i].sc); ans += get(z[i].sc); if(z[i].fr < 0) ans--; } cout << ans << '\n'; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); ll tt = 1; // scanf("%d", &tt); while(tt--){ solve(); } return 0; }
a.cc:14:1: error: ISO C++ forbids declaration of 'get' with no type [-fpermissive] 14 | get(int x){ | ^~~ a.cc:24:1: error: ISO C++ forbids declaration of 'upd' with no type [-fpermissive] 24 | upd(int x){ | ^~~ a.cc: In function 'int upd(int)': a.cc:28:1: warning: no return statement in function returning non-void [-Wreturn-type] 28 | } | ^
s796512096
p03703
C++
#include "bits/stdc++.h" #define ll long long #define fr first #define sc second using namespace std; const int mnx = 1e7 + 9; const int mod = 1e9 + 7; const double PI = acos(-1); ll n, k, a[mnx], t[mnx], h; pair <int, int> z[mnx]; get(int x){ ll res = 0; for(; x > 0; x -= (x & -x)){ res += t[x]; } return res; } upd(int x){ for(; x <= n; x += (x & -x)){ t[x]++; } } void solve(){ cin >> n >> k; for(int i = 1; i <= n; i++){ cin >> a[i]; a[i] -= k; } ll sum = 0; for(int i = 1; i <= n; i++){ sum += a[i]; z[i] = {sum, i}; } sort (z + 1, z + n + 1); ll ans = 0; for(int i = 1; i <= n; i++){ upd(z[i].sc); ans += get(z[i].sc); if(z[i].fr < 0) ans--; } cout << ans << '\n'; } int main(){ // ios_base::sync_with_stdio(0); // cin.tie(0), cout.tie(0); ll tt = 1; // scanf("%d", &tt); while(tt--){ solve(); } return 0; }
a.cc:14:1: error: ISO C++ forbids declaration of 'get' with no type [-fpermissive] 14 | get(int x){ | ^~~ a.cc:24:1: error: ISO C++ forbids declaration of 'upd' with no type [-fpermissive] 24 | upd(int x){ | ^~~ a.cc: In function 'int upd(int)': a.cc:28:1: warning: no return statement in function returning non-void [-Wreturn-type] 28 | } | ^
s603908775
p03703
C++
#include <iostream> #include <vector> #include <algorithm> #include <queue> #include <set> #include <string> #include <cmath> #include <map> #include <iomanip> #include <tuple> #define INF 1000000009 #define LINF 1000000000000000009 #define double long double #define all(a) a.begin(),a.end() using namespace std; typedef long long ll; typedef pair<ll, ll> P; //ll mod = 1000000007; //ll mod = 998244353; vector<ll> cnt(700010); void add(ll i, ll x) { i += 262143; cnt[i] += x; while (i > 0) { i = (i - 1) / 2; cnt[i] = cnt[i * 2 + 1] + cnt[i * 2 + 2]; } } ll query(ll a, ll b, ll k, ll l, ll r) { if (r <= a || b <= l) return 0; if (a <= l && r <= b) return cnt[k]; else { ll c1 = query(a, b, 2 * k + 1, l, (l + r) / 2); ll c2 = query(a, b, 2 * k + 2, (l + r) / 2, r); return c1 + c2; } } int main() { ll n, k; cin >> n >> k; vector<ll> a(n); for (int i = 0; i < n; i++) cin >> a[i]; vector<ll> s(n + 1); s[0] = 0; for (int i = 0; i < n; i++) s[i + 1] = s[i] + a[i] - k; map<ll, ll> mp; for (int i = 0; i <= n; i++) { s[i] += k * n; mp[s[i]]++; } vector<ll> t(n + 1); for (int i = 0; i <= n; i++) t[i] = s[i]; sort(all(t)); for (int i = 1; i <= n; i++) { if (t[i] != t[i - 1]) mp[t[i]] += mp[t[i - 1]]; } ll ans = 0; for (int i = 0; i <= n; i++) { s[i] = mp[s[i]]; ll res = query(262143, 262144 + s[i], 262143,524287); ans += res; add(s[i], 1); } cout << ans << endl; }
a.cc: In function 'int main()': a.cc:64:31: error: too few arguments to function 'll query(ll, ll, ll, ll, ll)' 64 | ll res = query(262143, 262144 + s[i], 262143,524287); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a.cc:32:4: note: declared here 32 | ll query(ll a, ll b, ll k, ll l, ll r) { | ^~~~~
s101978600
p03703
C++
#include <iostream> #include <vector> #include <algorithm> #include <utility> #include <queue> #include <set> #include <map> #define all(x) (x).begin(), (x).end() typedef long long ll; #define MOD 1000000007 using namespace std; //https://ei1333.github.io/luzhiled/snippets/structure/segment-tree.html template <typename Monoid> struct SegmentTree { using F = function<Monoid(Monoid, Monoid)>; int sz; vector<Monoid> seg; const F f; const Monoid M1; SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) { sz = 1; while (sz < n) sz <<= 1; seg.assign(2 * sz, M1); } void set(int k, const Monoid &x) { seg[k + sz] = x; } void build() { for (int k = sz - 1; k > 0; k--) { seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]); } } void update(int k, const Monoid &x) { k += sz; seg[k] = x; while (k >>= 1) { seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]); } } Monoid query(int a, int b) { Monoid L = M1, R = M1; for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) { if (a & 1) L = f(L, seg[a++]); if (b & 1) R = f(seg[--b], R); } return f(L, R); } Monoid operator[](const int &k) const { return seg[k + sz]; } template <typename C> int find_subtree(int a, const C &check, Monoid &M, bool type) { while (a < sz) { Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]); if (check(nxt)) a = 2 * a + type; else M = nxt, a = 2 * a + 1 - type; } return a - sz; } template <typename C> int find_first(int a, const C &check) { Monoid L = M1; if (a <= 0) { if (check(f(L, seg[1]))) return find_subtree(1, check, L, false); return -1; } int b = sz; for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) { if (a & 1) { Monoid nxt = f(L, seg[a]); if (check(nxt)) return find_subtree(a, check, L, false); L = nxt; ++a; } } return -1; } template <typename C> int find_last(int b, const C &check) { Monoid R = M1; if (b >= sz) { if (check(f(seg[1], R))) return find_subtree(1, check, R, true); return -1; } int a = sz; for (b += sz; a < b; a >>= 1, b >>= 1) { if (b & 1) { Monoid nxt = f(seg[--b], R); if (check(nxt)) return find_subtree(b, check, R, true); R = nxt; } } return -1; } }; int main() { ll n, k; cin >> n >> k; vector<ll> a(n); for (size_t i = 0; i < n; i++) { cin >> a[i]; } vector<ll> r(n + 1, 0), p(n + 1, 0); for (size_t i = 0; i < n; i++) { r[i + 1] = r[i] + a[i]; p[i + 1] = r[i + 1] - (i + 1) * k; } vector<ll> b = p; map<ll, ll> mp; sort(all(b)); for (int i = 0; i < n + 1; i++) { mp[b[i]] = i + 1; } ll ans = 0; SegmentTree<int> seg(n + 1, [](int a, int b) { return a + b; }, 0); seg.build(); for (int i = 0; i < n + 1; i++) { ans += seg.query(1, i + 1); seg.update(mp[p[i]], 1); } cout << ans << endl; }
a.cc:16:15: error: 'function' does not name a type; did you mean 'union'? 16 | using F = function<Monoid(Monoid, Monoid)>; | ^~~~~~~~ | union a.cc:21:11: error: 'F' does not name a type 21 | const F f; | ^ a.cc:24:30: error: 'F' does not name a type 24 | SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) | ^ a.cc: In constructor 'SegmentTree<Monoid>::SegmentTree(int, int, const Monoid&)': a.cc:24:55: error: class 'SegmentTree<Monoid>' does not have any field named 'f' 24 | SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) | ^ a.cc: In function 'int main()': a.cc:160:33: error: invalid user-defined conversion from 'main()::<lambda(int, int)>' to 'int' [-fpermissive] 160 | SegmentTree<int> seg(n + 1, [](int a, int b) { return a + b; }, 0); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a.cc:160:33: note: candidate is: 'constexpr main()::<lambda(int, int)>::operator int (*)(int, int)() const' (near match) 160 | SegmentTree<int> seg(n + 1, [](int a, int b) { return a + b; }, 0); | ^ a.cc:160:33: note: no known conversion from 'int (*)(int, int)' to 'int' a.cc:24:32: note: initializing argument 2 of 'SegmentTree<Monoid>::SegmentTree(int, int, const Monoid&) [with Monoid = int]' 24 | SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) | ~~~~~~~~^ a.cc: In instantiation of 'void SegmentTree<Monoid>::build() [with Monoid = int]': a.cc:161:14: required from here 161 | seg.build(); | ~~~~~~~~~^~ a.cc:41:23: error: 'f' was not declared in this scope 41 | seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]); | ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a.cc: In instantiation of 'Monoid SegmentTree<Monoid>::query(int, int) [with Monoid = int]': a.cc:164:25: required from here 164 | ans += seg.query(1, i + 1); | ~~~~~~~~~^~~~~~~~~~ a.cc:61:22: error: 'f' was not declared in this scope 61 | L = f(L, seg[a++]); | ~^~~~~~~~~~~~~ a.cc:63:22: error: 'f' was not declared in this scope 63 | R = f(seg[--b], R); | ~^~~~~~~~~~~~~ a.cc:65:17: error: 'f' was not declared in this scope 65 | return f(L, R); | ~^~~~~~ a.cc: In instantiation of 'void SegmentTree<Monoid>::update(int, const Monoid&) [with Monoid = int]': a.cc:165:19: required from here 165 | seg.update(mp[p[i]], 1); | ~~~~~~~~~~^~~~~~~~~~~~~ a.cc:51:23: error: 'f' was not declared in this scope 51 | seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]); | ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
s588973617
p03703
C++
#include <algorithm> #include <iostream> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef pair<ll, int> P; template<typename Monoid> struct SegmentTree { using F = function<Monoid(Monoid, Monoid)>; int sz; vector<Monoid> seg; const F f; const Monoid M1; SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) { sz = 1; while(sz < n) sz <<= 1; seg.assign(2 * sz, M1); } void set(int k, const Monoid &x) { seg[k + sz] = x; } void build() { for(int k = sz - 1; k > 0; k--) { seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]); } } void update(int k, const Monoid &x) { k += sz; seg[k] = x; while(k >>= 1) { seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]); } } Monoid query(int a, int b) { Monoid L = M1, R = M1; for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) { if(a & 1) L = f(L, seg[a++]); if(b & 1) R = f(seg[--b], R); } return f(L, R); } Monoid operator[](const int &k) const { return seg[k + sz]; } }; int main() { ll n, k; cin >> n >> k; ll a[200004]; ll s[200004]; P p[200004]; ll ans = 0; for(int i = 0; i < n; i++){ cin >> a[i]; a[i] -= k; s[i] = a[i]; if(i > 0) s[i] += s[i - 1]; if(s[i] >= 0) ans++; p[i] = P(s[i], i); } sort(p, p + n); int nth[200004]; for(int i = 0; i < n; i++) nth[p[i].second] = i; SegmentTree<ll> seg(n, [](ll a, ll b){return a + b;}, (ll)0); for(int i = 0; i < n; i++) seg.set(i, (ll)0); seg.build(); for(int i = n - 1; i >= 0; i--){ int insert = lower_bound(p, p + n, P(s[i], -1)) - p; ans += seg.query(insert, n); seg.update(nth[i], 1); } cout << ans << endl; }
a.cc:11:15: error: 'function' does not name a type; did you mean 'union'? 11 | using F = function<Monoid(Monoid, Monoid)>; | ^~~~~~~~ | union a.cc:16:11: error: 'F' does not name a type 16 | const F f; | ^ a.cc:19:30: error: 'F' does not name a type 19 | SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) { | ^ a.cc: In constructor 'SegmentTree<Monoid>::SegmentTree(int, int, const Monoid&)': a.cc:19:55: error: class 'SegmentTree<Monoid>' does not have any field named 'f' 19 | SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) { | ^ a.cc: In function 'int main()': a.cc:76:28: error: invalid user-defined conversion from 'main()::<lambda(ll, ll)>' to 'int' [-fpermissive] 76 | SegmentTree<ll> seg(n, [](ll a, ll b){return a + b;}, (ll)0); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a.cc:76:28: note: candidate is: 'constexpr main()::<lambda(ll, ll)>::operator long long int (*)(ll, ll)() const' (near match) 76 | SegmentTree<ll> seg(n, [](ll a, ll b){return a + b;}, (ll)0); | ^ a.cc:76:28: note: no known conversion from 'long long int (*)(ll, ll)' {aka 'long long int (*)(long long int, long long int)'} to 'int' a.cc:19:32: note: initializing argument 2 of 'SegmentTree<Monoid>::SegmentTree(int, int, const Monoid&) [with Monoid = long long int]' 19 | SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) { | ~~~~~~~~^ a.cc: In instantiation of 'void SegmentTree<Monoid>::build() [with Monoid = long long int]': a.cc:78:14: required from here 78 | seg.build(); | ~~~~~~~~~^~ a.cc:31:23: error: 'f' was not declared in this scope 31 | seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]); | ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a.cc: In instantiation of 'Monoid SegmentTree<Monoid>::query(int, int) [with Monoid = long long int]': a.cc:81:25: required from here 81 | ans += seg.query(insert, n); | ~~~~~~~~~^~~~~~~~~~~ a.cc:46:28: error: 'f' was not declared in this scope 46 | if(a & 1) L = f(L, seg[a++]); | ~^~~~~~~~~~~~~ a.cc:47:28: error: 'f' was not declared in this scope 47 | if(b & 1) R = f(seg[--b], R); | ~^~~~~~~~~~~~~ a.cc:49:17: error: 'f' was not declared in this scope 49 | return f(L, R); | ~^~~~~~ a.cc: In instantiation of 'void SegmentTree<Monoid>::update(int, const Monoid&) [with Monoid = long long int]': a.cc:82:19: required from here 82 | seg.update(nth[i], 1); | ~~~~~~~~~~^~~~~~~~~~~ a.cc:39:23: error: 'f' was not declared in this scope 39 | seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]); | ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
s221025726
p03703
C++
#include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<cmath> using namespace std; const int N=200005; struct node{ long long tot; int id; }; int n,k; long long a[N]; node b[N]; bool cmp(node a,node b) { return a.tot<b.tot; } int lowbit(int x) { return (x&-x); } void modify(int x,int tot) { if(x==0){ a[x]+=(long long)tot; return; } while(x<=n){ a[x]+=(long long)tot; x+=lowbit(x); } } long long sum(int x) { long long ans=a[0]; while(x>0){ ans+=a[x]; x-=lowbit(x); } return ans; } int main() { scanf("%d %d",&n,&k); b[0].tot=0;b[0].id=0; for(int i=1;i<=n;i++){ int x; scanf("%d",&x); b[i].tot=b[i-1].tot+(long long)(x-k); b[i].id=i; } sort(b,b+1+n); long long cnt=0; memset(a,0,sizeof(a)); for(int i=0;i<=n;i++){ if(b[i].id>0)cnt+=sum(b[i].id-1); modify(b[i].id,1); } printf("%lld\n",cnt); return 0; }
In file included from /usr/include/c++/14/bits/stl_algobase.h:71, from /usr/include/c++/14/algorithm:60, from a.cc:3: /usr/include/c++/14/bits/predefined_ops.h: In instantiation of 'constexpr bool __gnu_cxx::__ops::_Iter_less_iter::operator()(_Iterator1, _Iterator2) const [with _Iterator1 = node*; _Iterator2 = node*]': /usr/include/c++/14/bits/stl_algo.h:1777:14: required from 'void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = node*; _Compare = __gnu_cxx::__ops::_Iter_less_iter]' 1777 | if (__comp(__i, __first)) | ~~~~~~^~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_algo.h:1817:25: required from 'void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = node*; _Compare = __gnu_cxx::__ops::_Iter_less_iter]' 1817 | std::__insertion_sort(__first, __first + int(_S_threshold), __comp); | ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_algo.h:1908:31: required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = node*; _Compare = __gnu_cxx::__ops::_Iter_less_iter]' 1908 | std::__final_insertion_sort(__first, __last, __comp); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_algo.h:4772:18: required from 'void std::sort(_RAIter, _RAIter) [with _RAIter = node*]' 4772 | std::__sort(__first, __last, __gnu_cxx::__ops::__iter_less_iter()); | ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a.cc:60:9: required from here 60 | sort(b,b+1+n); | ~~~~^~~~~~~~~ /usr/include/c++/14/bits/predefined_ops.h:45:23: error: no match for 'operator<' (operand types are 'node' and 'node') 45 | { return *__it1 < *__it2; } | ~~~~~~~^~~~~~~~ In file included from /usr/include/c++/14/bits/stl_algobase.h:67: /usr/include/c++/14/bits/stl_iterator.h:1241:5: note: candidate: 'template<class _IteratorL, class _IteratorR, class _Container> bool __gnu_cxx::operator<(const __normal_iterator<_IteratorL, _Container>&, const __normal_iterator<_IteratorR, _Container>&)' 1241 | operator<(const __normal_iterator<_IteratorL, _Container>& __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/stl_iterator.h:1241:5: note: template argument deduction/substitution failed: /usr/include/c++/14/bits/predefined_ops.h:45:23: note: 'node' is not derived from 'const __gnu_cxx::__normal_iterator<_IteratorL, _Container>' 45 | { return *__it1 < *__it2; } | ~~~~~~~^~~~~~~~ /usr/include/c++/14/bits/stl_iterator.h:1249:5: note: candidate: 'template<class _Iterator, class _Container> bool __gnu_cxx::operator<(const __normal_iterator<_Iterator, _Container>&, const __normal_iterator<_Iterator, _Container>&)' 1249 | operator<(const __normal_iterator<_Iterator, _Container>& __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/stl_iterator.h:1249:5: note: template argument deduction/substitution failed: /usr/include/c++/14/bits/predefined_ops.h:45:23: note: 'node' is not derived from 'const __gnu_cxx::__normal_iterator<_Iterator, _Container>' 45 | { return *__it1 < *__it2; } | ~~~~~~~^~~~~~~~ /usr/include/c++/14/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Val_less_iter::operator()(_Value&, _Iterator) const [with _Value = node; _Iterator = node*]': /usr/include/c++/14/bits/stl_algo.h:1757:20: required from 'void std::__unguarded_linear_insert(_RandomAccessIterator, _Compare) [with _RandomAccessIterator = node*; _Compare = __gnu_cxx::__ops::_Val_less_iter]' 1757 | while (__comp(__val, __next)) | ~~~~~~^~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_algo.h:1785:36: required from 'void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = node*; _Compare = __gnu_cxx::__ops::_Iter_less_iter]' 1785 | std::__unguarded_linear_insert(__i, | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~ 1786 | __gnu_cxx::__ops::__val_comp_iter(__comp)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_algo.h:1817:25: required from 'void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = node*; _Compare = __gnu_cxx::__ops::_Iter_less_iter]' 1817 | std::__insertion_sort(__first, __first + int(_S_threshold), __comp); | ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_algo.h:1908:31: required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = node*; _Compare = __gnu_cxx::__ops::_Iter_less_iter]' 1908 | std::__final_insertion_sort(__first, __last, __comp); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_algo.h:4772:18: required from 'void std::sort(_RAIter, _RAIter) [with _RAIter = node*]' 4772 | std::__sort(__first, __last, __gnu_cxx::__ops::__iter_less_iter()); | ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a.cc:60:9: required from here 60 | sort(b,b+1+n); | ~~~~^~~~~~~~~ /usr/include/c++/14/bits/predefined_ops.h:98:22: error: no match for 'operator<' (operand types are 'node' and 'node') 98 | { return __val < *__it; } | ~~~~~~^~~~~~~ /usr/include/c++/14/bits/stl_iterator.h:1241:5: note: candidate: 'template<class _IteratorL, class _IteratorR, class _Container> bool __gnu_cxx::operator<(const __normal_iterator<_IteratorL, _Container>&, const __normal_iterator<_IteratorR, _Container>&)' 1241 | operator<(const __normal_iterator<_IteratorL, _Container>& __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/stl_iterator.h:1241:5: note: template argument deduction/substitution failed: /usr/include/c++/14/bits/predefined_ops.h:98:22: note: 'node' is not derived from 'const __gnu_cxx::__normal_iterator<_IteratorL, _Container>' 98 | { return __val < *__it; } | ~~~~~~^~~~~~~ /usr/include/c++/14/bits/stl_iterator.h:1249:5: note: candidate: 'template<class _Iterator, class _Container> bool __gnu_cxx::operator<(const __normal_iterator<_Iterator, _Container>&, const __normal_iterator<_Iterator, _Container>&)' 1249 | operator<(const __normal_iterator<_Iterator, _Container>& __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/stl_iterator.h:1249:5: note: template argument deduction/substitution failed: /usr/include/c++/14/bits/predefined_ops.h:98:22: note: 'node' is not derived from 'const __gnu_cxx::__normal_iterator<_Iterator, _Container>' 98 | { return __val < *__it; } | ~~~~~~^~~~~~~ /usr/include/c++/14/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Iter_less_val::operator()(_Iterator, _Value&) const [with _Iterator = node*; _Value = node]': /usr/include/c++/14/bits/stl_heap.h:140:48: required from 'void std::__push_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare&) [with _RandomAccessIterator = node*; _Distance = long int; _Tp = node; _Compare = __gnu_cxx::__ops::_Iter_less_val]' 140 | while (__holeIndex > __topIndex && __comp(__first + __parent, __value)) | ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_heap.h:247:23: required from 'void std::__adjust_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare) [with _RandomAccessIterator = node*; _Distance = long int; _Tp = node; _Compare = __gnu_cxx::__ops::_Iter_less_iter]' 247 | std::__push_heap(__first, __holeIndex, __topIndex, | ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 248 | _GLIBCXX_MOVE(__value), __cmp); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_heap.h:356:22: required from 'void std::__make_heap(_RandomAccessIterator, _RandomAccessIterator, _Compare&) [with _RandomAccessIterator = node*; _Compare = __gnu_cxx::__ops::_Iter_less_iter]' 356 | std::__adjust_heap(__first, __parent, __len, _GLIBCXX_MOVE(__value), | ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 357 | __comp); | ~~~~~~~ /usr/include/c++/14/bits/stl_algo.h:1593:23: required from 'void std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = node*; _Compare = __gnu_cxx::__ops::_Iter_less_iter]' 1593 | std::__make_heap(__first, __middle, __comp); | ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_algo.h:1868:25: required from 'void std::__partial_sort(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = node*; _Compare = __gnu_cxx::__ops::_Iter_less_iter]' 1868 | std::__heap_select(__first, __middle, __last, __comp); | ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_algo.h:1884:27: required from 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = node*; _Size = long int; _Compare = __gnu_cxx::__ops::_Iter_less_iter]' 1884 | std::__partial_sort(__first, __last, __last, __comp); | ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_algo.h:1905:25: required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = node*; _Compare = __gnu_cxx::__ops::_Iter_less_iter]' 1905 | std::__introsort_loop(__first, __last, | ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~ 1906 | s
s634923496
p03703
C++
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main(int argc, char** argv) { long long N, K; cin >> N >> K; vector<long long> a(N), a_sum(N+1); for (int i = 0; i < N; i++) cin >> a[i]; a_sum[0] = 0; for (int i = 1; i <= N; i++) a_sum[i] = a_sum[i - 1] + a[i - 1] - K; int ans = 0; int n_sqrt = int(sqrt(N)) + 1; vector<long long> a_sum_sorted; int n_sorted = int(N / n_sqrt) * n_sqrt; a_sum_sorted = vector<long long>(a_sum.begin(), a_sum.begin() + n_sorted); sort(a_sum_sorted.begin(), a_sum_sorted.end()); for (int j = N; j >= 1; j--) { if (j % n_sqrt == 0) { n_sorted -= n_sqrt; a_sum_sorted = vector<long long>(a_sum.begin(), a_sum.begin() + n_sorted); sort(a_sum_sorted.begin(), a_sum_sorted.end()); } // ソート済の部分は2分探索で ans += upper_bound(a_sum_sorted.begin(), a_sum_sorted.end(), a_sum[j]) - a_sum_sorted.begin(); // ソートしていない部分はナイーブに for (int i = j - 1; i >= n_sorted; i--) { ans += a_sum[j] >= a_sum[i]; } } cout << ans << endl; }
a.cc: In function 'int main(int, char**)': a.cc:24:26: error: 'sqrt' was not declared in this scope; did you mean 'n_sqrt'? 24 | int n_sqrt = int(sqrt(N)) + 1; | ^~~~ | n_sqrt
s828010208
p03703
C++
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vll; typedef vector<int> vi; typedef pair<ll, int> lli; typedef vector<lli> vlli; int bit[100010], N; //0--iまでの和 int sum(int i){ ans=0; while(i>0){ ans+=bits[i]; i-=i&-i; } return ans; } int add(int i, int x){ while(i<=n){ bits[i]+=x; i+=i&-i; } } int main(){ int N, K;cin>>N>>K; vll a; for (int i=0;i<N;++i){ int a_;cin>>a_;a.push_back(a_-K); } vll cumsum(N+1); cumsum[0]=0; for (int i=0;i<N;++i){ cumsum[i+1]=cumsum[i]+a[i]; } vlli c(N); for (int i=0;i<N;++i){ c[i]=make_pair(cumsum[i+1], i); } sort(c.begin(), c.end()); vll d(N); for (int i=0;i<N;++i){ d[c[i].second]=i; } ll ans=0; for(int j=0;j<N;++j){ ans+=sum(d[j]); add(d[j], 1); } cout << ans << endl; return 0; }
a.cc: In function 'int sum(int)': a.cc:14:3: error: 'ans' was not declared in this scope; did you mean 'abs'? 14 | ans=0; | ^~~ | abs a.cc:16:10: error: 'bits' was not declared in this scope; did you mean 'bit'? 16 | ans+=bits[i]; | ^~~~ | bit a.cc: In function 'int add(int, int)': a.cc:23:12: error: 'n' was not declared in this scope 23 | while(i<=n){ | ^ a.cc:24:5: error: 'bits' was not declared in this scope; did you mean 'bit'? 24 | bits[i]+=x; | ^~~~ | bit a.cc:27:1: warning: no return statement in function returning non-void [-Wreturn-type] 27 | } | ^
s683302891
p03703
C++
#include <iostream> #include <algorithm> #include <vector> using namespace std; struct BIT { int N; vector<int> data; explicit BIT(int n) : N(n + 1), data(n + 1) {} void add(int i, int v) { for(int x = i; x < N; x += x & -x) { data[x] += v; } } int get(int i) { int ret = 0; for(int x = i; x > 0; x -= x & -x) { ret += data[x]; } return ret; } }; int main() { int N, K; cin >> N >> K; vector<ll> A(N); for(int i = 0; i < N; i++) { cin >> A[i]; A[i] -= K; } vector<ll> acc(N + 1); for(int i = 0; i < N; i++) { acc[i + 1] = acc[i] + A[i]; } vector<ll> acc_ = acc; sort(acc_.begin(), acc_.end()); BIT bit(N + 1); ll ans = 0; for(int i = 0; i < N + 1; i++) { int k = lower_bound(acc_.begin(), acc_.end(), acc[i]) - acc.begin() + 1; ans += bit.get(k); bit.add(k, 1); } cout << ans << endl; return 0; }
a.cc: In function 'int main()': a.cc:28:10: error: 'll' was not declared in this scope 28 | vector<ll> A(N); | ^~ a.cc:28:12: error: template argument 1 is invalid 28 | vector<ll> A(N); | ^ a.cc:28:12: error: template argument 2 is invalid a.cc:30:13: error: invalid types 'int[int]' for array subscript 30 | cin >> A[i]; | ^ a.cc:31:6: error: invalid types 'int[int]' for array subscript 31 | A[i] -= K; | ^ a.cc:33:12: error: template argument 2 is invalid 33 | vector<ll> acc(N + 1); | ^ a.cc:35:8: error: invalid types 'int[int]' for array subscript 35 | acc[i + 1] = acc[i] + A[i]; | ^ a.cc:35:21: error: invalid types 'int[int]' for array subscript 35 | acc[i + 1] = acc[i] + A[i]; | ^ a.cc:35:28: error: invalid types 'int[int]' for array subscript 35 | acc[i + 1] = acc[i] + A[i]; | ^ a.cc:37:12: error: template argument 2 is invalid 37 | vector<ll> acc_ = acc; | ^ a.cc:38:13: error: request for member 'begin' in 'acc_', which is of non-class type 'int' 38 | sort(acc_.begin(), acc_.end()); | ^~~~~ a.cc:38:27: error: request for member 'end' in 'acc_', which is of non-class type 'int' 38 | sort(acc_.begin(), acc_.end()); | ^~~ a.cc:41:5: error: expected ';' before 'ans' 41 | ll ans = 0; | ^~~~ | ; a.cc:43:30: error: request for member 'begin' in 'acc_', which is of non-class type 'int' 43 | int k = lower_bound(acc_.begin(), acc_.end(), acc[i]) - acc.begin() + 1; | ^~~~~ a.cc:43:44: error: request for member 'end' in 'acc_', which is of non-class type 'int' 43 | int k = lower_bound(acc_.begin(), acc_.end(), acc[i]) - acc.begin() + 1; | ^~~ a.cc:43:54: error: invalid types 'int[int]' for array subscript 43 | int k = lower_bound(acc_.begin(), acc_.end(), acc[i]) - acc.begin() + 1; | ^ a.cc:43:65: error: request for member 'begin' in 'acc', which is of non-class type 'int' 43 | int k = lower_bound(acc_.begin(), acc_.end(), acc[i]) - acc.begin() + 1; | ^~~~~ a.cc:44:9: error: 'ans' was not declared in this scope; did you mean 'abs'? 44 | ans += bit.get(k); | ^~~ | abs a.cc:47:11: error: 'ans' was not declared in this scope; did you mean 'abs'? 47 | cout << ans << endl; | ^~~ | abs
s424725431
p03703
C++
#include <iostream> #include <algorithm> #include <vector> #include <map> #include <string> #include <cmath> #include <iomanip> #include <numeric> #include <set> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) FOR(i, 0, n) #define SORT(c) sort((c).begin(), (c).end()) typedef long long ll; typedef pair<int, int> P; typedef vector<int> V; typedef map<int, int> M; int bit[11234567], bit_n; int bit_sum(int i) { int s = 0; while (i > 0) { s += bit[i]; i -= i & -i; } return s; } void bit_add(int i, int x) { while (i <= bit_n) { bit[i] += x; i += i & -i; } } int main() { int n; ll k, a[212345]; cin >> n >> k; REP(i, n) { cin >> a[i]; a[i] -= k; } set<ll> num; ll sum[212345]; sum[0] = 0; num.insert(0); REP(i, n) { sum[i + 1] = sum[i] + a[i]; num.insert(sum[i + 1]); } vector<ll> nv; for (ll i : num) nv.push_back(i); SORT(nv); map<ll, int> mp; REP(i, nv.size()) mp[nv[i]] = i; for (int i = 0; i <= n; i++) sum[i] = mp[sum[i]]; memset(bit, 0, sizeof(bit)); bit_n = nv.size(); ll res = 0; for (int i = 0; i <= n; i++) { res += bit_sum(sum[i] + 1); bit_add(sum[i] + 1, 1); } cout << res << endl; return 0; }
a.cc: In function 'int main()': a.cc:82:5: error: 'memset' was not declared in this scope 82 | memset(bit, 0, sizeof(bit)); | ^~~~~~ a.cc:10:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>' 9 | #include <set> +++ |+#include <cstring> 10 |
s212620658
p03703
C++
#include <iostream> #include <algorithm> #include<cmath> #include<cstring> #include<cstdio> #include<cstdlib> #include<vector> #include<ctime> #include<set> #include<iomanip> #define sqr(x) (x)*(x) #define fz1(i,n) for ((i)=1;(i)<=(n);(i)++) #define fd1(i,n) for ((i)=(n);(i)>=1;(i)--) #define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++) #define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--) #define fz0k(i,n) for ((i)=0;(i)<(n);(i)++) #define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--) #define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++) #define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--) #define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++) #define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;} //#define long long long long using namespace std; int n,i,j,rt,cnt,l[200005],r[200005],sz[200005],rnd[200005]; long long ans,m,a[200005],val[200005]; int nwnd(int x) { cnt++; l[cnt]=r[cnt]=0; sz[cnt]=1;val[cnt]=x;rnd[cnt]=rand()*32768+rand(); return cnt; } void pushup(long long x) { sz[x]=1+sz[l[x]]+sz[r[x]]; } void split(long long x,long long y,long long &sl,long long &sr) { if (!x) { sl=sr=0; return; } if (val[x]<=y) { split(r[x],y,r[x],sr); sl=x; pushup(x); return; } else { split(l[x],y,sl,l[x]); sr=x; pushup(x); return; } } long long merge(long long x,long long y) { if (!x||!y) return x+y; if (rnd[x]>rnd[y]) { r[x]=merge(r[x],y); pushup(x); return x; } else { l[y]=merge(x,l[y]); pushup(y); return y; } } int main() { cin>>n>>m; fz1(i,n) { cin>>a[i]; a[i]-=m; a[i]+=a[i-1]; } rt=nwnd(0); fz1(i,n) { long long t1,t2; split(rt,a[i],t1,t2); ans+=sz[t1]; rt=merge(merge(t1,nwnd(a[i])),t2); } cout<<ans<<endl; return 0; }
a.cc: In function 'void split(long long int, long long int, long long int&, long long int&)': a.cc:46:33: error: cannot bind non-const lvalue reference of type 'long long int&' to a value of type 'int' 46 | split(r[x],y,r[x],sr); | ~~~^ a.cc:37:47: note: initializing argument 3 of 'void split(long long int, long long int, long long int&, long long int&)' 37 | void split(long long x,long long y,long long &sl,long long &sr) | ~~~~~~~~~~~^~ a.cc:53:36: error: cannot bind non-const lvalue reference of type 'long long int&' to a value of type 'int' 53 | split(l[x],y,sl,l[x]); | ~~~^ a.cc:37:61: note: initializing argument 4 of 'void split(long long int, long long int, long long int&, long long int&)' 37 | void split(long long x,long long y,long long &sl,long long &sr) | ~~~~~~~~~~~^~
s994986927
p03703
C++
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN=500005; ll ans,a[MAXN],s[MAXN],c[MAXN],ss[MAXN],n,k; map to; ll lowbit(ll x){ return x & -x; } void change(ll x,ll y){ while (x<=n){ // printf("%d ",x); c[x]+=y; x+=lowbit(x); } return; } ll sum(ll x){ ll s=0; while (x>=1){ s+=c[x]; x-=lowbit(x); } return s; } int main(){ int i; scanf("%lld%lld",&n,&k); for (i=1;i<=n;i++){ scanf("%lld",&a[i]); a[i]-=k; s[i]=s[i-1]+a[i]; ss[i]=ss[i-1]+a[i]; if (s[i]>=0) ans++; } change(s[1],1ll); for (i=2;i<=n;i++){ ans+=sum(s[i]); change(s[i],1ll); // printf("%lld ",ans); } // printf("\n"); printf("%lld",ans); return 0; }
a.cc:11:5: error: class template argument deduction failed: 11 | map to; | ^~ a.cc:11:5: error: no matching function for call to 'map()' In file included from /usr/include/c++/14/map:63, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:152, from a.cc:2: /usr/include/c++/14/bits/stl_map.h:302:9: note: candidate: 'template<class _Key, class _Tp, class _Compare, class _Alloc, class _InputIterator> map(_InputIterator, _InputIterator, const _Compare&, const _Alloc&)-> std::map<_Key, _Tp, _Compare, _Alloc>' 302 | map(_InputIterator __first, _InputIterator __last, | ^~~ /usr/include/c++/14/bits/stl_map.h:302:9: note: candidate expects 3 arguments, 0 provided /usr/include/c++/14/bits/stl_map.h:285:9: note: candidate: 'template<class _Key, class _Tp, class _Compare, class _Alloc, class _InputIterator> map(_InputIterator, _InputIterator)-> std::map<_Key, _Tp, _Compare, _Alloc>' 285 | map(_InputIterator __first, _InputIterator __last) | ^~~ /usr/include/c++/14/bits/stl_map.h:285:9: note: candidate expects 2 arguments, 0 provided /usr/include/c++/14/bits/stl_map.h:268:9: note: candidate: 'template<class _Key, class _Tp, class _Compare, class _Alloc, class _InputIterator> map(_InputIterator, _InputIterator, const _Alloc&)-> std::map<_Key, _Tp, _Compare, _Alloc>' 268 | map(_InputIterator __first, _InputIterator __last, | ^~~ /usr/include/c++/14/bits/stl_map.h:268:9: note: candidate expects 3 arguments, 0 provided /usr/include/c++/14/bits/stl_map.h:262:7: note: candidate: 'template<class _Key, class _Tp, class _Compare, class _Alloc> map(std::initializer_list<std::pair<const _Key, _Val> >, const _Alloc&)-> std::map<_Key, _Tp, _Compare, _Alloc>' 262 | map(initializer_list<value_type> __l, const allocator_type& __a) | ^~~ /usr/include/c++/14/bits/stl_map.h:262:7: note: candidate expects 2 arguments, 0 provided /usr/include/c++/14/bits/stl_map.h:256:7: note: candidate: 'template<class _Key, class _Tp, class _Compare, class _Alloc> map(std::map<_Key, _Tp, _Compare, _Allocator>&&, std::__type_identity_t<_Alloc>&)-> std::map<_Key, _Tp, _Compare, _Alloc>' 256 | map(map&& __m, const __type_identity_t<allocator_type>& __a) | ^~~ /usr/include/c++/14/bits/stl_map.h:256:7: note: candidate expects 2 arguments, 0 provided /usr/include/c++/14/bits/stl_map.h:252:7: note: candidate: 'template<class _Key, class _Tp, class _Compare, class _Alloc> map(const std::map<_Key, _Tp, _Compare, _Allocator>&, std::__type_identity_t<_Alloc>&)-> std::map<_Key, _Tp, _Compare, _Alloc>' 252 | map(const map& __m, const __type_identity_t<allocator_type>& __a) | ^~~ /usr/include/c++/14/bits/stl_map.h:252:7: note: candidate expects 2 arguments, 0 provided /usr/include/c++/14/bits/stl_map.h:248:7: note: candidate: 'template<class _Key, class _Tp, class _Compare, class _Alloc> map(const _Alloc&)-> std::map<_Key, _Tp, _Compare, _Alloc>' 248 | map(const allocator_type& __a) | ^~~ /usr/include/c++/14/bits/stl_map.h:248:7: note: candidate expects 1 argument, 0 provided /usr/include/c++/14/bits/stl_map.h:240:7: note: candidate: 'template<class _Key, class _Tp, class _Compare, class _Alloc> map(std::initializer_list<std::pair<const _Key, _Val> >, const _Compare&, const _Alloc&)-> std::map<_Key, _Tp, _Compare, _Alloc>' 240 | map(initializer_list<value_type> __l, | ^~~ /usr/include/c++/14/bits/stl_map.h:240:7: note: candidate expects 1 argument, 0 provided /usr/include/c++/14/bits/stl_map.h:227:7: note: candidate: 'template<class _Key, class _Tp, class _Compare, class _Alloc> map(std::map<_Key, _Tp, _Compare, _Allocator>&&)-> std::map<_Key, _Tp, _Compare, _Alloc>' 227 | map(map&&) = default; | ^~~ /usr/include/c++/14/bits/stl_map.h:227:7: note: candidate expects 1 argument, 0 provided /usr/include/c++/14/bits/stl_map.h:219:7: note: candidate: 'template<class _Key, class _Tp, class _Compare, class _Alloc> map(const std::map<_Key, _Tp, _Compare, _Allocator>&)-> std::map<_Key, _Tp, _Compare, _Alloc>' 219 | map(const map&) = default; | ^~~ /usr/include/c++/14/bits/stl_map.h:219:7: note: candidate expects 1 argument, 0 provided /usr/include/c++/14/bits/stl_map.h:206:7: note: candidate: 'template<class _Key, class _Tp, class _Compare, class _Alloc> map(const _Compare&, const _Alloc&)-> std::map<_Key, _Tp, _Compare, _Alloc>' 206 | map(const _Compare& __comp, | ^~~ /usr/include/c++/14/bits/stl_map.h:206:7: note: candidate expects 1 argument, 0 provided /usr/include/c++/14/bits/stl_map.h:197:7: note: candidate: 'template<class _Key, class _Tp, class _Compare, class _Alloc> map()-> std::map<_Key, _Tp, _Compare, _Alloc>' 197 | map() = default; | ^~~ /usr/include/c++/14/bits/stl_map.h:197:7: note: template argument deduction/substitution failed: a.cc:11:5: note: couldn't deduce template parameter '_Key' 11 | map to; | ^~ /usr/include/c++/14/bits/stl_map.h:102:11: note: candidate: 'template<class _Key, class _Tp, class _Compare, class _Alloc> map(std::map<_Key, _Tp, _Compare, _Alloc>)-> std::map<_Key, _Tp, _Compare, _Alloc>' 102 | class map | ^~~ /usr/include/c++/14/bits/stl_map.h:102:11: note: candidate expects 1 argument, 0 provided /usr/include/c++/14/bits/stl_map.h:1495:5: note: candidate: 'template<class _Key, class _Tp, class _Allocator, class> std::map(initializer_list<pair<_T1, _T2> >, _Allocator)-> map<_Key, _Tp, less<_Key>, _Allocator>' 1495 | map(initializer_list<pair<_Key, _Tp>>, _Allocator) | ^~~ /usr/include/c++/14/bits/stl_map.h:1495:5: note: candidate expects 2 arguments, 0 provided /usr/include/c++/14/bits/stl_map.h:1489:5: note: candidate: 'template<class _InputIterator, class _Allocator, class, class> std::map(_InputIterator, _InputIterator, _Allocator)-> map<typename remove_const<typename iterator_traits< <template-parameter-1-1> >::value_type::first_type>::type, typename iterator_traits< <template-parameter-1-1> >::value_type::second_type, less<typename remove_const<typename iterator_traits< <template-parameter-1-1> >::value_type::first_type>::type>, _Allocator>' 1489 | map(_InputIterator, _InputIterator, _Allocator) | ^~~ /usr/include/c++/14/bits/stl_map.h:1489:5: note: candidate expects 3 arguments, 0 provided /usr/include/c++/14/bits/stl_map.h:1482:5: note: candidate: 'template<class _Key, class _Tp, class _Compare, class _Allocator, class, class> std::map(initializer_list<pair<_T1, _T2> >, _Compare, _Allocator)-> map<_Key, _Tp, _Compare, _Allocator>' 1482 | map(initializer_list<pair<_Key, _Tp>>, | ^~~ /usr/include/c++/14/bits/stl_map.h:1482:5: note: candidate expects 1 argument, 0 provided /usr/include/c++/14/bits/stl_map.h:1473:5: note: candidate: 'template<class _InputIterator, class _Compare, class _Allocator, class, class, class> std::map(_InputIterator, _InputIterator, _Compare, _Allocator)-> map<typename remove_const<typename iterator_traits< <template-parameter-1-1> >::value_type::first_type>::type, typename iterator_traits< <template-parameter-1-1> >::value_type::second_type, _Compare, _Allocator>' 1473 | map(_InputIterator, _InputIterator, | ^~~ /usr/include/c++/14/bits/stl_map.h:1473:5: note: candidate expects 2 arguments, 0 provided
s815895840
p03703
C++
#include<bits/stdc++.h> using namespace std; long long aa;bool bb;char ch; long long scan() { while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-'); ch=='-'?(bb=1,aa=0):(bb=0,aa=ch-48); while(ch=getchar(),(ch>='0'&&ch<='9')) aa=aa*10+ch-48; return (bb?(-aa):(aa)); } //用树状数组求逆序数 long long Length; struct Node { long long data; long long pos; }; Node seq[200010]; long long TreeArray[200010]; long long LowBit(long long num) { return num&(num^(num-1)); } long long cmp(Node num1,Node num2) { if(num2.data==num1.data) return num1.pos<num2.pos; return num1.data>num2.data; } long long sum(long long pos) { long long result=0; while (pos) { result+=TreeArray[pos]; pos-=LowBit(pos); } return result; } void INC(long long pos) { while(pos<=Length) { TreeArray[pos]++; pos+=LowBit(pos); } } void insertNum(long long &reverseNum) { for (long long i=1;i<=Length;i++) { reverseNum+=sum(seq[i].pos); //cout<<i<<" "<<seq[i].data<<"\t"<<seq[i].pos<<"\t"<<reverseNum<<endl; INC(seq[i].pos); } } long long n,k; long long array[200010]; int main() { scanf("%lld%lld",&n,&k); Length=n+1; for(int i=1;i<=n;++i) array[i]=scan()-k; for(int i=2;i<=n;++i) array[i]=array[i-1]+array[i]; seq[1].data=0; seq[1].pos=1; for(int i=1;i<=n;i++) { seq[i+1].data=-array[i]; seq[i+1].pos=i+1; } //从大到小排序 sort(seq+1,seq+Length+1,cmp); //for(int i=1;i<=Length;i++) // cout<<seq[i].data<<" "<<seq[i].pos<<endl; //cout<<endl; long long reverseNum=0; insertNum(reverseNum); cout<<reverseNum<<endl; return 0; }
a.cc: In function 'int main()': a.cc:66:17: error: reference to 'array' is ambiguous 66 | array[i]=scan()-k; | ^~~~~ In file included from /usr/include/c++/14/bits/stl_algobase.h:64, from /usr/include/c++/14/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51, from a.cc:1: /usr/include/c++/14/bits/stl_pair.h:99:12: note: candidates are: 'template<class _Tp, long unsigned int _Nm> struct std::array' 99 | struct array; | ^~~~~ a.cc:60:11: note: 'long long int array [200010]' 60 | long long array[200010]; | ^~~~~ a.cc:68:17: error: reference to 'array' is ambiguous 68 | array[i]=array[i-1]+array[i]; | ^~~~~ /usr/include/c++/14/bits/stl_pair.h:99:12: note: candidates are: 'template<class _Tp, long unsigned int _Nm> struct std::array' 99 | struct array; | ^~~~~ a.cc:60:11: note: 'long long int array [200010]' 60 | long long array[200010]; | ^~~~~ a.cc:68:26: error: reference to 'array' is ambiguous 68 | array[i]=array[i-1]+array[i]; | ^~~~~ /usr/include/c++/14/bits/stl_pair.h:99:12: note: candidates are: 'template<class _Tp, long unsigned int _Nm> struct std::array' 99 | struct array; | ^~~~~ a.cc:60:11: note: 'long long int array [200010]' 60 | long long array[200010]; | ^~~~~ a.cc:68:37: error: reference to 'array' is ambiguous 68 | array[i]=array[i-1]+array[i]; | ^~~~~ /usr/include/c++/14/bits/stl_pair.h:99:12: note: candidates are: 'template<class _Tp, long unsigned int _Nm> struct std::array' 99 | struct array; | ^~~~~ a.cc:60:11: note: 'long long int array [200010]' 60 | long long array[200010]; | ^~~~~ a.cc:73:24: error: reference to 'array' is ambiguous 73 | seq[i+1].data=-array[i]; | ^~~~~ /usr/include/c++/14/bits/stl_pair.h:99:12: note: candidates are: 'template<class _Tp, long unsigned int _Nm> struct std::array' 99 | struct array; | ^~~~~ a.cc:60:11: note: 'long long int array [200010]' 60 | long long array[200010]; | ^~~~~
s726119503
p03703
C++
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define N 200010 using namespace std; int n,k, long long ans=0,aux[N],sum[N]; long long tree[N<<2]; int lowbit(int x) { return x&-x; } long long getsum(int x) { long long ans=0; for(int i=x;i;i-=lowbit(i)) ans+=tree[i]; return ans; } void add(int x,int k) { for(int i=x;i<=n;i+=lowbit(i)) tree[i]+=k; } int main() { memset(sum,0,sizeof(sum)); memset(aux,0,sizeof(aux)); scanf("%d%d",&n,&k); for(int i=1;i<=n;i++) { int x; scanf("%d",&x); sum[i]=sum[i-1]+x-k; aux[i]=sum[i]; } sort(aux+1,aux+1+n); int m=unique(aux+1,aux+1+n)-aux; for(int i=0;i<=n;i++) sum[i]=lower_bound(aux+1,aux+1+m,sum[i])-aux+1; for(int i=0;i<=n;i++) { ans+=getsum(sum[i]); add(sum[i],1); } printf("%lld\n",ans); }
a.cc:8:1: error: expected unqualified-id before 'long' 8 | long long ans=0,aux[N],sum[N]; | ^~~~ a.cc: In function 'int main()': a.cc:29:16: error: 'sum' was not declared in this scope 29 | memset(sum,0,sizeof(sum)); | ^~~ a.cc:30:16: error: 'aux' was not declared in this scope 30 | memset(aux,0,sizeof(aux)); | ^~~ a.cc:45:17: error: 'ans' was not declared in this scope; did you mean 'abs'? 45 | ans+=getsum(sum[i]); | ^~~ | abs a.cc:48:25: error: 'ans' was not declared in this scope; did you mean 'abs'? 48 | printf("%lld\n",ans); | ^~~ | abs
s551676479
p03703
C++
#include <bits/stdc++.h> #define lowbit(x) x & -x using namespace std; const int N = 1e5 + 10; typedef long long LL: LL n, k; LL a[N], sum[N], c[N]; inline void insert(LL x) { for(; x <= n; x += lowbit(x)) c[x] += 1; } inline LL query(LL x) { int ans = 0; for(; x; x -= lowbit(x)) ans += c[x]; return ans; } inline LL find(LL x) { LL mid, l = 1, r = n + 1; while(l <= r) { mid = l + ((r - l) >> 1); if(sum[mid] == x) return mid; else if(sum[mid] < x) l = mid + 1; else if(sum[mid] > x) r = mid - 1; } return mid; } int main() { cin >> n >> k; for(LL i = 1; i <= n; ++i) { cin >> a[i], a[i] -= k; sum[i] = sum[i - 1] + a[i];//记录前缀和 a[i] = sum[i]; } sum[n + 1] = 0; sort(sum + 1, sum + n + 2); LL ans = 0; for(LL i = 0; i <= n; ++i) { LL rk = find(a[i]); ans += query(rk); // printf("rk = %d %d\n", a[i], query(rk)); insert(rk);//更新要放在查询的后面 } printf("%lld", ans); return 0; }
a.cc:8:21: error: found ':' in nested-name-specifier, expected '::' 8 | typedef long long LL: | ^ | :: a.cc:8:19: error: 'LL' has not been declared 8 | typedef long long LL: | ^~ a.cc:10:4: error: expected initializer before 'n' 10 | LL n, k; | ^ a.cc:11:1: error: 'LL' does not name a type 11 | LL a[N], sum[N], c[N]; | ^~ a.cc:13:13: error: variable or field 'insert' declared void 13 | inline void insert(LL x) { | ^~~~~~ a.cc:13:20: error: 'LL' was not declared in this scope 13 | inline void insert(LL x) { | ^~ a.cc:18:8: error: 'LL' does not name a type 18 | inline LL query(LL x) { | ^~ a.cc:25:8: error: 'LL' does not name a type 25 | inline LL find(LL x) { | ^~ a.cc: In function 'int main()': a.cc:37:16: error: 'n' was not declared in this scope 37 | cin >> n >> k; | ^ a.cc:37:21: error: 'k' was not declared in this scope 37 | cin >> n >> k; | ^ a.cc:38:13: error: 'LL' was not declared in this scope 38 | for(LL i = 1; i <= n; ++i) { | ^~ a.cc:38:23: error: 'i' was not declared in this scope 38 | for(LL i = 1; i <= n; ++i) { | ^ a.cc:39:24: error: 'a' was not declared in this scope 39 | cin >> a[i], a[i] -= k; | ^ a.cc:40:17: error: 'sum' was not declared in this scope 40 | sum[i] = sum[i - 1] + a[i];//记录前缀和 | ^~~ a.cc:43:9: error: 'sum' was not declared in this scope 43 | sum[n + 1] = 0; | ^~~ a.cc:45:9: error: 'LL' was not declared in this scope 45 | LL ans = 0; | ^~ a.cc:46:15: error: expected ';' before 'i' 46 | for(LL i = 0; i <= n; ++i) { | ^~ | ; a.cc:46:23: error: 'i' was not declared in this scope 46 | for(LL i = 0; i <= n; ++i) { | ^ a.cc:47:19: error: expected ';' before 'rk' 47 | LL rk = find(a[i]); | ^~~ | ; a.cc:48:17: error: 'ans' was not declared in this scope; did you mean 'abs'? 48 | ans += query(rk); | ^~~ | abs a.cc:48:30: error: 'rk' was not declared in this scope; did you mean 'brk'? 48 | ans += query(rk); | ^~ | brk a.cc:48:24: error: 'query' was not declared in this scope 48 | ans += query(rk); | ^~~~~ a.cc:50:17: error: 'insert' was not declared in this scope; did you mean 'assert'? 50 | insert(rk);//更新要放在查询的后面 | ^~~~~~ | assert a.cc:52:24: error: 'ans' was not declared in this scope; did you mean 'abs'? 52 | printf("%lld", ans); | ^~~ | abs
s347333142
p03703
C++
#include <bits/stdc++.h> typedef long long LL; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) using namespace std; random_device rnd; mt19937 mt(rnd()); class Myset { Myset *lch, *rch; LL value; LL size; Myset* update() { this->size = sz(this->lch) + 1 + sz(this->rch); return this; } Myset* _push(Myset *ch) { if (ch->value == this->value) { ++this->size; this->push(ch->lch); this->push(ch->rch); } else if(ch->value < this->value) { !this->lch ? this->lch = ch : this->lch = this->lch->push(ch); } else { !this->rch ? this->rch = ch : this->rch = this->rch->push(ch); } return this->update(); } public: static int sz(Myset *s) { return !s ? 0 : s->size; } Myset() : lch(NULL), rch(NULL), value(0), size(1), pri(mt()) {} Myset(LL v) : lch(NULL), rch(NULL), value(v), size(1), pri(mt()) {} Myset* push(Myset *s) { if(!this || !s) return !this ? s : this; uniform_int_distribution<> r(1, this->size + s->size); if(r(mt) <= this->size) { return this->_push(s); } else { return s->_push(this); } } LL count_le(LL x) { if(!this) return 0; if(this->value <= x) { return sz(this->lch) + 1 + this->rch->count_le(x); } else { return this->lch->count_le(x); } } void dump(int d = 0) { if(lch) lch->dump(d+1); cout << d << " " << this->size << " " << this->value << endl; if(rch) rch->dump(d+1); } }; Myset pool[262144]; int main(void) { int n; LL k; cin >> n >> k; vector<LL> a(n); REP(i, n) { cin >> a[i]; a[i] -= k; } LL sum = 0ll; LL answer = 0ll; pool[n] = Myset(0); Myset* root = &pool[n]; REP(i, n) { sum += a[i]; answer += root->count_le(sum); pool[i] = Myset(sum); root = root->push(&pool[i]); } cout << answer << endl; return 0; }
a.cc: In constructor 'Myset::Myset()': a.cc:37:54: error: class 'Myset' does not have any field named 'pri' 37 | Myset() : lch(NULL), rch(NULL), value(0), size(1), pri(mt()) {} | ^~~ a.cc: In constructor 'Myset::Myset(LL)': a.cc:38:58: error: class 'Myset' does not have any field named 'pri' 38 | Myset(LL v) : lch(NULL), rch(NULL), value(v), size(1), pri(mt()) {} | ^~~
s008528006
p03703
C++
#include <bits/stdc++.h> #define int long long using namespace std; const int N = 2e5 + 5; int n, k, a[N], used[N], cnt = 0; long long f[N], bit[N]; vector <pair <long long, int> > comp; void update (int x, int val) { for (int i = x; i < N; i += i & -i) bit[i] += val; } long long get (int x) { long long ans = 0; for (int i = x; i > 0; i -= i & -i) ans += bit[i]; return ans; } int main(){ scanf("%lld %lld", &n, &k); long long ans = 0; f[0] = 0; for (int i = 1; i <= n; i++) scanf("%lld", &a[i]); for (int i = 1; i <= n; i++) f[i] = f[i - 1] + a[i]; for (int i = 1; i <= n; i++) comp.push_back(make_pair(f[i] - k * i, i)); comp.push_back(make_pair(0, 0)); sort(comp.begin(), comp.end()); used[comp[0].second] = ++cnt; for (int i = 1; i < comp.size(); i++) { if (comp[i].first > comp[i - 1].first) used[comp[i].second] = ++cnt; else used[comp[i].second] = cnt; } for (int i = 1; i <= n; i++) { update(used[i - 1], 1); ans += get(used[i]); } printf("%lld", ans); return 0; }
cc1plus: error: '::main' must return 'int'
s405283256
p03703
Java
import java.io.*; import java.math.*; import java.util.*; import static java.util.Arrays.fill; import static java.lang.Math.*; import static java.util.Arrays.sort; import static java.util.Collections.sort; public class MeaningfulMean { public static int mod = 1000000007; public static long INF = (1L << 60); static FastScanner2 in = new FastScanner2(); static OutputWriter out = new OutputWriter(System.out); static long[] bit; static int n; public static void update(int x,int delta) { for(;x<=n;x+=(x&-x)) { bit[x]+=delta; } } public static long query(int x) { long ret=0; for(;x>0;x-=(x&-x)) { ret+=bit[x]; } return ret; } public static void main(String[] args) { n=in.nextInt(); long k=in.nextInt(); long ans=0; long[] arr=new long[n+1]; for(int i=1;i<=n;i++) { arr[i]=in.nextLong(); } bit=new long[n+1]; long[] a=new long[n+1]; List<Long> sumList = new ArrayList<Long>(); for(int i=1;i<=n;i++) { a[i]=a[i-1]+arr[i]-k; sumList.add(a[i]); } Collections.sort(sumList); int current = 1; Map<Long, Integer> map = new HashMap<>(); for (long value : sumList) { map.put(value, current++); } for(int i=0;i<=n;i++) { ans+=query(map.get(a[i])); update(map.get(a[i]), 1); } out.println(ans); out.close(); } static class FastScanner2 { private byte[] buf = new byte[1024]; private int curChar; private int snumChars; public int read() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = System.in.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndOfLine(c)); return res.toString(); } public String nextString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int nextInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = nextInt(); } return arr; } public long[] nextLongArray(int n) { long[] arr = new long[n]; for (int i = 0; i < n; i++) { arr[i] = nextLong(); } return arr; } private boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream inputstream) { reader = new BufferedReader(new InputStreamReader(inputstream)); tokenizer = null; } public String nextLine() { String fullLine = null; while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { fullLine = reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } return fullLine; } return fullLine; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public long nextLong() { return Long.parseLong(next()); } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } public long[] nextLongArray(int n) { long a[] = new long[n]; for (int i = 0; i < n; i++) { a[i] = nextLong(); } return a; } public int nextInt() { return Integer.parseInt(next()); } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) writer.print(' '); writer.print(objects[i]); } } public void println(Object... objects) { print(objects); writer.println(); } public void close() { writer.close(); } public void flush() { writer.flush(); } } private static boolean oj = System.getProperty("ONLINE_JUDGE") != null; private static void debug(Object... o) { if (!oj) System.out.println(Arrays.deepToString(o)); } private static void tr(Object... o) { if (!oj) System.out.println(Arrays.deepToString(o)); } }
Main.java:10: error: class MeaningfulMean is public, should be declared in a file named MeaningfulMean.java public class MeaningfulMean { ^ 1 error
s473013735
p03703
C++
#include <bits/stdc++.h> using namespace std; #define ll long long const int mod=1e9+7; ll ll cnt=0; void fun(ll length,ll k) { ll sum=0; ll num=0; ll flag=-1,flag1=1; ll n=pow((float)2,length); for(int i=0; i<n; i++) { sum=0; num=0; flag=-1; flag1=1; ll temp=i; for(int j=0; j<length; j++) { if(temp&1) { if(flag==-1) { flag=j; sum+=a[j]; num++; } else if(j==flag+1) { flag++; sum+=a[j]; num++; } else { flag1=0; break; } } temp=temp>>1; } if(flag1&&num&&sum/num>=k) { cnt++; } } } int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); ll i,j,k,m,n; cin>>n>>k; for(i=0; i<n; i++) { cin>>a[i]; } fun(n,k); cout<<cnt<<endl; return 0; }
a.cc:3:12: error: 'long long long' is too long for GCC 3 | #define ll long long | ^~~~ a.cc:6:1: note: in expansion of macro 'll' 6 | ll cnt=0; | ^~ a.cc:3:17: error: 'long long long' is too long for GCC 3 | #define ll long long | ^~~~ a.cc:6:1: note: in expansion of macro 'll' 6 | ll cnt=0; | ^~ a.cc: In function 'void fun(long long int, long long int)': a.cc:27:26: error: 'a' was not declared in this scope 27 | sum+=a[j]; | ^ a.cc:33:26: error: 'a' was not declared in this scope 33 | sum+=a[j]; | ^ a.cc: In function 'int main()': a.cc:59:14: error: 'a' was not declared in this scope 59 | cin>>a[i]; | ^
s971409415
p03703
C++
#include<bits/stdc++.h> #define ll long long using namespace std; const int maxn=200005; ll num[maxn],a[maxn],ans; int n,rank[maxn],f[maxn],k,ky; inline int read(){ int x=0; char ch=getchar(); for(;!isdigit(ch);ch=getchar()); for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0'; return x; } inline void update(int x,int y){ for(;x<=ky;x+=x&-x) f[x]+=y;} inline int query(int x){ int an=0; for(;x;x-=x&-x) an+=f[x]; return an;} int main(){ scanf("%d%d",&n,&k); for(int i=1;i<=n;i++) a[i]=read()-k; for(int i=1;i<=n;i++){ a[i]+=a[i-1],num[i]=a[i]; if(a[i]>=0) ans++; } sort(num+1,num+n+1); ky=unique(num+1,num+n+1)-num-1; for(int i=1;i<=n;i++) rank[i]=lower_bound(num+1,num+ky+1,a[i])-num; for(int i=1;i<=n;i++) ans+=(ll)query(rank[i]),update(rank[i],1); printf("%lld\n",ans); return 0; }
a.cc: In function 'int main()': a.cc:24:31: error: reference to 'rank' is ambiguous 24 | for(int i=1;i<=n;i++) rank[i]=lower_bound(num+1,num+ky+1,a[i])-num; | ^~~~ In file included from /usr/include/c++/14/bits/stl_pair.h:60, from /usr/include/c++/14/bits/stl_algobase.h:64, from /usr/include/c++/14/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51, from a.cc:1: /usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank' 1437 | struct rank | ^~~~ a.cc:6:7: note: 'int rank [200005]' 6 | int n,rank[maxn],f[maxn],k,ky; | ^~~~ a.cc:25:46: error: reference to 'rank' is ambiguous 25 | for(int i=1;i<=n;i++) ans+=(ll)query(rank[i]),update(rank[i],1); | ^~~~ /usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank' 1437 | struct rank | ^~~~ a.cc:6:7: note: 'int rank [200005]' 6 | int n,rank[maxn],f[maxn],k,ky; | ^~~~ a.cc:25:62: error: reference to 'rank' is ambiguous 25 | for(int i=1;i<=n;i++) ans+=(ll)query(rank[i]),update(rank[i],1); | ^~~~ /usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank' 1437 | struct rank | ^~~~ a.cc:6:7: note: 'int rank [200005]' 6 | int n,rank[maxn],f[maxn],k,ky; | ^~~~
s394782713
p03703
C++
#include<bits/stdc++.h> #define ll long long using namespace std; const int maxn=200005; ll num[maxn],a[maxn],ans; int n,rank[maxn],f[maxn],k,ky; inline int read(){ int x=0; char ch=getchar(); for(;!isdigit(ch);ch=getchar()); for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0'; return x; } inline void update(int x,int y){ for(;x<=ky;x+=x&-x) f[x]+=y;} inline int query(int x){ int an=0; for(;x;x-=x&-x) an+=f[x]; return an;} int main(){ scanf("%d%d",&n,&k); for(int i=1;i<=n;i++) a[i]=read()-k; for(int i=1;i<=n;i++){ a[i]+=a[i-1],num[i]=a[i]; if(a[i]>=0) ans++; } sort(num+1,num+n+1); ky=unique(num+1,num+n+1)-num-1; for(int i=1;i<=n;i++) rank[i]=lower_bound(num+1,num+ky+1,a[i])-num; for(int i=1;i<=n;i++) ans+=(ll)query(rank[i]),update(rank[i],1); printf("%lld\n",ans); return 0; }
a.cc: In function 'int main()': a.cc:24:31: error: reference to 'rank' is ambiguous 24 | for(int i=1;i<=n;i++) rank[i]=lower_bound(num+1,num+ky+1,a[i])-num; | ^~~~ In file included from /usr/include/c++/14/bits/stl_pair.h:60, from /usr/include/c++/14/bits/stl_algobase.h:64, from /usr/include/c++/14/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51, from a.cc:1: /usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank' 1437 | struct rank | ^~~~ a.cc:6:7: note: 'int rank [200005]' 6 | int n,rank[maxn],f[maxn],k,ky; | ^~~~ a.cc:25:46: error: reference to 'rank' is ambiguous 25 | for(int i=1;i<=n;i++) ans+=(ll)query(rank[i]),update(rank[i],1); | ^~~~ /usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank' 1437 | struct rank | ^~~~ a.cc:6:7: note: 'int rank [200005]' 6 | int n,rank[maxn],f[maxn],k,ky; | ^~~~ a.cc:25:62: error: reference to 'rank' is ambiguous 25 | for(int i=1;i<=n;i++) ans+=(ll)query(rank[i]),update(rank[i],1); | ^~~~ /usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank' 1437 | struct rank | ^~~~ a.cc:6:7: note: 'int rank [200005]' 6 | int n,rank[maxn],f[maxn],k,ky; | ^~~~
s182647384
p03703
C++
#include<iostream> #define MAX 200002 #define MAX_A 1000000002 using namespace std; int a[MAX]; int l[MAX / 2 + 2], r[MAX / 2 + 2]; long long Merge(int a[], int n, int left, int mid, int right) { int i, j; long long cnt = 0; int n1 = mid - left; int n2 = right - mid; for (i = 0; i < n1; i++) { l[i] = a[left + i]; } for (i = 0; i < n2; i++) { r[i] = a[mid + i]; } l[n1] = MAX_A; r[n2] = MAX_A; i = 0; j = 0; for (int k = left; k < right; k++) { if (l[i] < r[j]) { a[k] = l[i]; i++; } else { a[k] = r[j]; j++; cnt += n1 - i; } } return cnt; } long long MergeSort(int A[], int n, int left, int right) { int mid; long long v1, v2, v3; if (left + 1 < right) { mid = (left + right) / 2; v1 = MergeSort(A, n, left, mid); v2 = MergeSort(A, n, mid, right); v3 = Merge(A, n, left, mid, right); return v1 + v2 + v3; } else { return 0; } } int main() { int n, k; cin >> n >> k; for (int i = 0; i < n; i++) { int x; cin >> x; a[i] = x - k; } for (int i = 1; i < n; i++) { a[i] = a[i - 1] + a[i]; } reverse(a, a + n); a[n] = 0; for (int i = 0; i < n; i++) { } cout << MergeSort(a, n+1, 0, n+1) << endl; }
a.cc: In function 'int main()': a.cc:59:9: error: 'reverse' was not declared in this scope 59 | reverse(a, a + n); | ^~~~~~~
s262309593
p03703
C++
#include <bits/stdc++.h> #define maxn 200010 using namespace std; typedef long long LL; LL c[maxn], a[maxn], b[maxn]; int n, k; int lowbit(int x) { return x & (-x); } LL query(int x) { LL ret=0; while (x) ret += c[x], x -= lowbit(x); return ret; } void add(int x) { while (x <= tot) ++c[x], x += lowbit(x); } int main() { scanf("%d%d", &n, &k); for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]), a[i] -= k; for (int i = 1; i <= n; ++i) b[i] = (a[i] += a[i-1]); b[n+1] = 0; sort(b+1, b+2+n); int tot = unique(b+1, b+2+n) - (b+1); LL ans=0; a[0] = 0; for (int i = 0; i <= n; ++i) { int p = lower_bound(b+1, b+1+tot, a[i]) - b; ans += query(p); add(p); } printf("%lld\n", ans); return 0; }
a.cc: In function 'void add(int)': a.cc:9:31: error: 'tot' was not declared in this scope 9 | void add(int x) { while (x <= tot) ++c[x], x += lowbit(x); } | ^~~
s725848722
p03703
C++
#include <iostream> #include <vector> #include <deque> #include <math.h> #include <set> #include <iomanip> #include <time.h> #include <list> #include <stdio.h> #include <queue> #include <map> #include <algorithm> #include <assert.h> #include <memory.h> #define mk make_pair #define sc second #define fr first #define pb emplace_back #define all(s) s.begin(), s.end() #define sz(s) ( (int)s.size() ) #define int long long using namespace std; const int N = 2e5 + 5; int n, k; long long ar[N], b[N]; long long ans; void Merge_sort(int l, int r) { if (l == r) return; int md = (l + r) >> 1; int i = l, j = md + 1; Merge_sort(l, md); Merge_sort(md + 1, r); for (int e = l; e <= r; e++) { if ( i <= md && ( j > r || ar[i] <= ar[j] ) ) { ans += ; b[e] = ar[i++]; } else b[e] = ar[j++]; } for (int e = l; e <= r; e++) ar[e] = b[e]; } main () { cin >> n >> k; for (int i = 1; i <= n; i++) { scanf("%lld", &ar[i]), ar[i] -= k; ar[i] += ar[i - 1]; } Merge_sort(0, n); cout << ans; }
a.cc: In function 'void Merge_sort(long long int, long long int)': a.cc:49:20: error: expected primary-expression before ';' token 49 | ans += ; | ^ a.cc: At global scope: a.cc:59:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 59 | main () | ^~~~
s293837753
p03703
C++
//#include "IntMod.h" //typedef IntMod<1000000007> MInt; //#include "Union_Find.h" #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <string> #include <vector> #include <utility> #include <algorithm> #include <functional> #include <cmath> #include <stack> #include <queue> #include <set> #include <map> #include <iomanip> #include <sstream> #include <numeric> #include <list> #include <bitset> using namespace std; #define REP(i,a,n) for(int i = (a); i < (int)(n); ++i) #define REPM(i,n,a) for(int i = ((n) - 1); i >= (a); --i) #define EPS 0.0001 #define INF 0x3FFFFFFF #define INFLL 0x3FFFFFFF3FFFFFFF #define INFD 1.0e+308 #define FLOAT setprecision(16) typedef long long LL; typedef unsigned long long ULL; typedef pair<LL, LL> PP; template <class T, class U> istream& operator>>(istream& ist, pair<T, U>& right) { return ist >> right.first >> right.second; } template <class T, class U> ostream& operator<<(ostream& ost, pair<T, U>& right) { return ost << right.first << ' ' << right.second; } template <class T, class TCompatible, size_t N> void Fill(T(&dest)[N], const TCompatible& val) { fill(begin(dest), end(dest), val); } template <class T, class TCompatible, size_t M, size_t N> void Fill(T(&dest)[M][N], const TCompatible& val) { for (int i = 0; i < M; ++i) Fill(dest[i], val); } //sum, 累積和 // 負のときの割り算に注意 #if 1 #include <array> #include <unordered_set> #include <unordered_map> template<class T> using PriorityQ = priority_queue<T, vector<T>, greater<T> >; // コスト小を優先 #endif template <typename T> class SegmentTree { using FuncType = std::function<T(const T&, const T&)>; private: T* val_p_m; const T init_val_m; const int size_m; const int rank_m; const FuncType func_m; T Query_rec(int range_left, int range_right, int node_index, int node_range_left, int node_range_right); bool Is_valid_index(int index); public: SegmentTree(int size, const T& init_val, const FuncType& func); void Update(int pos, const T& val); T Query(int range_left, int range_right); }; template<typename T> T SegmentTree<T>::Query_rec(int range_left, int range_right, int node_index, int node_range_left, int node_range_right) { if (node_range_right <= range_left || range_right <= node_range_left) return init_val_m; if (range_left <= node_range_left && node_range_right <= range_right) return val_p_m[node_index]; int node_range_mid = (node_range_left + node_range_right) / 2; const T val_left = Query_rec(range_left, range_right, node_index * 2, node_range_left, node_range_mid); const T val_right = Query_rec(range_left, range_right, node_index * 2 + 1, node_range_mid, node_range_right); return func_m(val_left, val_right); } template<typename T> inline bool SegmentTree<T>::Is_valid_index(int index) { return index >= 0 && index < size_m; } template<typename T> SegmentTree<T>::SegmentTree(int size, const T& init_val, const FuncType& func) : init_val_m(init_val), size_m(size), rank_m((int)std::log2(size) + 1), func_m(func) { val_p_m = new T[1 << rank_m]; fill(val_p_m + (1 << (rank_m - 1)), val_p_m + (1 << rank_m), init_val_m); for (int i = (1 << (rank_m - 1)) - 1; i >= 1; --i) { val_p_m[i] = func_m(val_p_m[i * 2], val_p_m[i * 2 + 1]); } } template<typename T> void SegmentTree<T>::Update(int pos, const T& val) { assert(Is_valid_index(pos)); int i = pos + (1 << (rank_m - 1)); val_p_m[i] = val; while (i > 1) { i /= 2; val_p_m[i] = func_m(val_p_m[i * 2], val_p_m[i * 2 + 1]); } } template<typename T> T SegmentTree<T>::Query(int range_left, int range_right) { assert(Is_valid_index(range_left)); assert(Is_valid_index(range_right - 1)); return Query_rec(range_left, range_right, 1, 0, 1 << (rank_m - 1)); } template<typename T> class Max { public: const T& operator()(const T& a, const T& b) const { return max<T>(a, b); } }; template<typename T> class Min { public: const T& operator()(const T& a, const T& b) const { return min<T>(a, b); } }; LL N, F; LL A[100000]; LL B[100001]; map<LL, vector<int> > M; vector<PP> C; int main() { cin >> N >> F; REP(i, 0, N) { cin >> A[i]; } B[0] = 0; REP(i, 1, N + 1) { B[i] = B[i - 1] + A[i - 1] - F; } REP(i, 0, N + 1) { M[B[i]].push_back(i); } int c = 0; for (auto&& p : M) { for (int i : p.second) { C.push_back(PP(i, c)); } ++c; } sort(C.begin(), C.end()); LL ans = 0; SegmentTree<int> S(N + 1, 0, plus<int>()); REP(i, 0, N + 1) { ans += S.Query(0, C[i].second + 1); S.Update(C[i].second, S.Query(C[i].second, C[i].second + 1) + 1); } cout << ans << endl; return 0; }
a.cc: In instantiation of 'T SegmentTree<T>::Query(int, int) [with T = int]': a.cc:173:17: required from here 173 | ans += S.Query(0, C[i].second + 1); | ~~~~~~~^~~~~~~~~~~~~~~~~~~~ a.cc:121:15: error: 'assert' was not declared in this scope 121 | assert(Is_valid_index(range_left)); | ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~ a.cc:51:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>' 50 | #include <unordered_set> +++ |+#include <cassert> 51 | #include <unordered_map> a.cc:122:15: error: 'assert' was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation 122 | assert(Is_valid_index(range_right - 1)); | ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a.cc:121:15: note: 'assert' declared here, later in the translation unit 121 | assert(Is_valid_index(range_left)); | ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~ a.cc: In instantiation of 'void SegmentTree<T>::Update(int, const T&) [with T = int]': a.cc:174:11: required from here 174 | S.Update(C[i].second, S.Query(C[i].second, C[i].second + 1) + 1); | ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a.cc:109:15: error: 'assert' was not declared in this scope 109 | assert(Is_valid_index(pos)); | ~~~~~~^~~~~~~~~~~~~~~~~~~~~ a.cc:109:15: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
s242304853
p03703
C++
80 75 73 93 73 73 10101 97 -1 -1 114 -1 10113 118
a.cc:1:1: error: expected unqualified-id before numeric constant 1 | 80 75 73 93 73 73 10101 97 -1 -1 114 -1 10113 118 | ^~
s594606091
p03703
C++
#include <bits/stdc++.h> using namespace std; using ll = long long; int const N = 200 * 1000 + 16; int a[N]; int n, k; struct node { static mt19937 rd = mt19937(time(0)); ll x; int s = 1; int y = rd(); node* l = 0; node* r = 0; node(ll v) { x = v; } ~node() { delete l; delete r; } node* upd() { s = 1; s += l ? l->s : 0; s += r ? r->s : 0; return this; } }; struct treap { node* root = 0; ~treap() { delete root; } node* join(node* l, node* r) { if(not l) return r; if(not r) return l; if(l->y < r->y) { l->r = join(l->r, r); return l->upd(); } else { r->l = join(l, r->l); return r->upd(); } } pair<node*,node*> split(node* p, ll x) { if(not p) return make_pair(nullptr,nullptr); if(x < p->x) { auto t = split(p->l, x); p->l = t.second; t.second = p->upd(); return t; } else { auto t = split(p->r, x); p->r = t.first; t.first = p->upd(); return t; } } void insert(ll x) { auto t = split(root, x); root = join(t.first, join(new node(x), t.second)); } int query(ll x) { auto t = split(root, x); int cnt = t.first ? t.first->s : 0; root = join(t.first, t.second); return cnt; } }; int main() { cin.tie(0); cin.sync_with_stdio(0); cin >> n >> k; copy_n(istream_iterator<int>(cin), n, a); treap t; t.insert(0); ll ans = 0; ll sum = 0; for(int i = 0; i < n; ++i) { sum += a[i]; ll v = sum - 1ll * i * k - k; ans += t.query(v); t.insert(sum - 1ll * (i+1) * k); } cout << ans << endl; }
a.cc:12:18: error: in-class initialization of static data member 'std::mt19937 node::rd' of non-literal type 12 | static mt19937 rd = mt19937(time(0)); | ^~ a.cc:12:38: error: call to non-'constexpr' function 'std::mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::mersenne_twister_engine(result_type) [with _UIntType = long unsigned int; long unsigned int __w = 32; long unsigned int __n = 624; long unsigned int __m = 397; long unsigned int __r = 31; _UIntType __a = 2567483615; long unsigned int __u = 11; _UIntType __d = 4294967295; long unsigned int __s = 7; _UIntType __b = 2636928640; long unsigned int __t = 15; _UIntType __c = 4022730752; long unsigned int __l = 18; _UIntType __f = 1812433253; result_type = long unsigned int]' 12 | static mt19937 rd = mt19937(time(0)); | ^ In file included from /usr/include/c++/14/random:48, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:179, from a.cc:1: /usr/include/c++/14/bits/random.h:647:7: note: 'std::mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::mersenne_twister_engine(result_type) [with _UIntType = long unsigned int; long unsigned int __w = 32; long unsigned int __n = 624; long unsigned int __m = 397; long unsigned int __r = 31; _UIntType __a = 2567483615; long unsigned int __u = 11; _UIntType __d = 4294967295; long unsigned int __s = 7; _UIntType __b = 2636928640; long unsigned int __t = 15; _UIntType __c = 4022730752; long unsigned int __l = 18; _UIntType __f = 1812433253; result_type = long unsigned int]' declared here 647 | mersenne_twister_engine(result_type __sd) | ^~~~~~~~~~~~~~~~~~~~~~~
s332409965
p03703
C++
#include <bits/stdc++.h> using namespace std; using ll = long long; int const N = 200 * 1000 + 16; int a[N]; int n, k; struct node { static mt19937 rd(time(0)); ll x; int s = 1; int y = rd(); node* l = 0; node* r = 0; node(ll v) { x = v; } ~node() { delete l; delete r; } node* upd() { s = 1; s += l ? l->s : 0; s += r ? r->s : 0; return this; } }; struct treap { node* root = 0; ~treap() { delete root; } node* join(node* l, node* r) { if(not l) return r; if(not r) return l; if(l->y < r->y) { l->r = join(l->r, r); return l->upd(); } else { r->l = join(l, r->l); return r->upd(); } } pair<node*,node*> split(node* p, ll x) { if(not p) return make_pair(nullptr,nullptr); if(x < p->x) { auto t = split(p->l, x); p->l = t.second; t.second = p->upd(); return t; } else { auto t = split(p->r, x); p->r = t.first; t.first = p->upd(); return t; } } void insert(ll x) { auto t = split(root, x); root = join(t.first, join(new node(x), t.second)); } int query(ll x) { auto t = split(root, x); int cnt = t.first ? t.first->s : 0; root = join(t.first, t.second); return cnt; } }; int main() { cin.tie(0); cin.sync_with_stdio(0); cin >> n >> k; copy_n(istream_iterator<int>(cin), n, a); treap t; t.insert(0); ll ans = 0; ll sum = 0; for(int i = 0; i < n; ++i) { sum += a[i]; ll v = sum - 1ll * i * k - k; ans += t.query(v); t.insert(sum - 1ll * (i+1) * k); } cout << ans << endl; }
a.cc:12:21: error: 'time' is not a type 12 | static mt19937 rd(time(0)); | ^~~~ a.cc:12:26: error: expected ')' before numeric constant 12 | static mt19937 rd(time(0)); | ~^ | ) a.cc:12:26: error: expected ')' before numeric constant 12 | static mt19937 rd(time(0)); | ~ ^ | ) a.cc:12:25: error: expected ';' at end of member declaration 12 | static mt19937 rd(time(0)); | ^ | ; a.cc:12:26: error: expected unqualified-id before numeric constant 12 | static mt19937 rd(time(0)); | ^ a.cc:15:13: error: cannot convert 'std::mt19937' {aka 'std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>'} to 'int' in initialization 15 | int y = rd(); | ~~^~ | | | std::mt19937 {aka std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>}
s882648786
p03703
C++
#include<iostream> #include<cstring> #include<cstdlib> #include<cstdio> #include<algorithm> #define ll long long using namespace std; struct poi{ll sum,pos;}a[200010]; ll n,k,ans,cnt,tree[200010],lisan[200010]; void read(ll &k) { k=0;int f=1;char c=getchar(); while(c<‘0‘||c>‘9‘)c==‘-‘&&(f=-1),c=getchar(); while(c<=‘9‘&&c>=‘0‘)k=k*10+c-‘0‘,c=getchar(); k*=f; } bool cmp(poi a,poi b){return a.sum<b.sum;} int lowbit(int x){return x&-x;} void add(int x,int delta) { for(int i=x;i<=cnt;i+=lowbit(i)) tree[i]+=delta; } int sum(int x) { int s=0; for(int i=x;i>=1;i-=lowbit(i)) s+=tree[i]; return s; } int main() { read(n);read(k); for(int i=1;i<=n;i++)read(a[i].sum),a[i].sum-=k; for(int i=1;i<=n;i++)a[i].sum+=a[i-1].sum,a[i].pos=i; sort(a,a+1+n,cmp); for(int i=0;i<=n;i++) { if(a[i].sum!=a[i-1].sum||i==0)cnt++; lisan[a[i].pos]=cnt; } for(int i=n;i>=0;i--) { ans+=sum(cnt)-sum(lisan[i]-1); add(lisan[i],1); } printf("%lld\n",ans); }
a.cc:13:13: error: extended character ‘ is not valid in an identifier 13 | while(c<‘0‘||c>‘9‘)c==‘-‘&&(f=-1),c=getchar(); | ^ a.cc:13:13: error: extended character ‘ is not valid in an identifier a.cc:13:20: error: extended character ‘ is not valid in an identifier 13 | while(c<‘0‘||c>‘9‘)c==‘-‘&&(f=-1),c=getchar(); | ^ a.cc:13:20: error: extended character ‘ is not valid in an identifier a.cc:13:27: error: extended character ‘ is not valid in an identifier 13 | while(c<‘0‘||c>‘9‘)c==‘-‘&&(f=-1),c=getchar(); | ^ a.cc:13:29: error: extended character ‘ is not valid in an identifier 13 | while(c<‘0‘||c>‘9‘)c==‘-‘&&(f=-1),c=getchar(); | ^ a.cc:14:14: error: extended character ‘ is not valid in an identifier 14 | while(c<=‘9‘&&c>=‘0‘)k=k*10+c-‘0‘,c=getchar(); | ^ a.cc:14:14: error: extended character ‘ is not valid in an identifier a.cc:14:22: error: extended character ‘ is not valid in an identifier 14 | while(c<=‘9‘&&c>=‘0‘)k=k*10+c-‘0‘,c=getchar(); | ^ a.cc:14:22: error: extended character ‘ is not valid in an identifier a.cc:14:35: error: extended character ‘ is not valid in an identifier 14 | while(c<=‘9‘&&c>=‘0‘)k=k*10+c-‘0‘,c=getchar(); | ^ a.cc:14:35: error: extended character ‘ is not valid in an identifier a.cc: In function 'void read(long long int&)': a.cc:13:13: error: '\U000020180\U00002018' was not declared in this scope 13 | while(c<‘0‘||c>‘9‘)c==‘-‘&&(f=-1),c=getchar(); | ^~~ a.cc:13:20: error: '\U000020189\U00002018' was not declared in this scope 13 | while(c<‘0‘||c>‘9‘)c==‘-‘&&(f=-1),c=getchar(); | ^~~ a.cc:13:27: error: '\U00002018' was not declared in this scope 13 | while(c<‘0‘||c>‘9‘)c==‘-‘&&(f=-1),c=getchar(); | ^ a.cc:14:14: error: '\U000020189\U00002018' was not declared in this scope 14 | while(c<=‘9‘&&c>=‘0‘)k=k*10+c-‘0‘,c=getchar(); | ^~~ a.cc:14:22: error: '\U000020180\U00002018' was not declared in this scope 14 | while(c<=‘9‘&&c>=‘0‘)k=k*10+c-‘0‘,c=getchar(); | ^~~
s779492377
p03703
C
#include<cstdio> #include<cstring> #include<string> #include<cmath> #include<iostream> #include<algorithm> #include<map> using namespace std; #define INF 0x3f3f3f3f typedef long long LL; const int MAX_N = 200000 +10; int f[MAX_N][20]; int query(int i,int j) { int k = log2(j-i+1); return max(f[i][k],f[j-(1 << k)+1][k]); } int main() { int n,m,x; scanf("%d%d",&n,&m); for (int i=1;i<=n;i++) scanf("%d",&f[i][0]); for (int j = 1; j < 19; ++j) for(int i = 1; i <= n; ++i) if(i + (1 << j) - 1 <= n) f[i][j] = max(f[i][j - 1], f[i + (1 << (j - 1))][j - 1]); int L,R,mid,ans = 0; for (int i=1;i<=n;i++){ L = i; R = n; while (L<=R){ mid = (L + R) >> 1; if (query(i,mid)>=m) R = mid-1; else L = mid+1; } //printf("%d %d\n",i,L); ans += n-L+1; } printf("%d\n",ans); }
main.c:1:9: fatal error: cstdio: No such file or directory 1 | #include<cstdio> | ^~~~~~~~ compilation terminated.
s300956958
p03703
C++
#include<iostream> #include<cstdio> #include<map> #include<algorithm> using namespace std; typedef long long ll; map<ll,int> t; int cnt; const int N=2e5+5; int n;ll k,a[N]={0},as[N]; int bit[N]={0}; void add(int x,int val) { while(x<cnt) bit[x]+=val,x+=x&-x; } int sum(int x) { int s=0;while(x) s+=bit[x],x-=x&-x;return s; } int main() { scanf("%d%lld",&n,&k); t.clear(); for(int i=1;i<=n;i++) scanf("%lld",a+i),a[i]-=k,a[i]+=a[i-1],as[i]=a[i]; ll ans=0; sort(as+1,as+1+n); cnt=1; for(int i=1;i<=n;i++) if(!t.count(as[i])) t[as[i]]=cnt++; for(int i=1;i<=n;i++) { if(a[i]>=0) ans++; ans+=sum(t[a[i]]); add(t[a[i]],1);a } printf("%lld\n",ans); return 0; }
a.cc: In function 'int main()': a.cc:29:25: error: expected ';' before '}' token 29 | add(t[a[i]],1);a | ^ | ; 30 | } | ~
s584855321
p03703
C++
#include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; const int maxn=200005; struct node { ll index,value; }a[maxn]; ll C[maxn],n,k; //离散化排序; int cmp1(node a,node b) { if(a.value!=b.value) return a.value<b.value; return a.index<b.index; } int cmp2(node a,node b) { if(a.index!=b.index) return a.index<b.index; return a.value<b.value; } ll lowbit(ll x) { return x&(-x); } void add(ll x,ll d) { while(x<maxn) { C[x]+=d; x+=lowbit(x); } } ll sum(ll x) { ll ret=0; while(x>0) { ret+=C[x]; x-=lowbit(x); } return ret; } int main() { ll ans=0; scanf("%lld%lld",&n,&k); for(int i=1;i<=n;i++) { scanf("%lld",&a[i].value); a[i].index=i; a[i].value-=k; } for(int i=2;i<=n;i++) a[i].value=a[i-1].value+a[i].value; for(int i=1;i<=n;i++) if(a[i].value>=0) ans+=1; //printf("%d\n",ans); sort(a+1,a+1+n,cmp1); for(int i=1;i<=n;i++) a[i].value=i; sort(a+1,a+1+n,cmp2); //for(int i=1;i<=n;i++) // printf("%d ",a[i].value); // printf("\n"); for(int i=1;i<=n;i++) { ll x=a[i].value; ans+=sum(x); add(x,1); } printf("%lld\n",ans); return 0; } /* 10 7 4 6 8 13 11 3 2 6 12 14 */
a.cc:10:5: error: 'll' does not name a type 10 | ll index,value; | ^~ a.cc:12:1: error: 'll' does not name a type 12 | ll C[maxn],n,k; | ^~ a.cc: In function 'int cmp1(node, node)': a.cc:17:10: error: 'struct node' has no member named 'value' 17 | if(a.value!=b.value) | ^~~~~ a.cc:17:19: error: 'struct node' has no member named 'value' 17 | if(a.value!=b.value) | ^~~~~ a.cc:18:18: error: 'struct node' has no member named 'value' 18 | return a.value<b.value; | ^~~~~ a.cc:18:26: error: 'struct node' has no member named 'value' 18 | return a.value<b.value; | ^~~~~ a.cc:19:14: error: 'struct node' has no member named 'index' 19 | return a.index<b.index; | ^~~~~ a.cc:19:22: error: 'struct node' has no member named 'index' 19 | return a.index<b.index; | ^~~~~ a.cc: In function 'int cmp2(node, node)': a.cc:24:10: error: 'struct node' has no member named 'index' 24 | if(a.index!=b.index) | ^~~~~ a.cc:24:19: error: 'struct node' has no member named 'index' 24 | if(a.index!=b.index) | ^~~~~ a.cc:25:18: error: 'struct node' has no member named 'index' 25 | return a.index<b.index; | ^~~~~ a.cc:25:26: error: 'struct node' has no member named 'index' 25 | return a.index<b.index; | ^~~~~ a.cc:26:14: error: 'struct node' has no member named 'value' 26 | return a.value<b.value; | ^~~~~ a.cc:26:22: error: 'struct node' has no member named 'value' 26 | return a.value<b.value; | ^~~~~ a.cc: At global scope: a.cc:29:1: error: 'll' does not name a type 29 | ll lowbit(ll x) | ^~ a.cc:34:6: error: variable or field 'add' declared void 34 | void add(ll x,ll d) | ^~~ a.cc:34:10: error: 'll' was not declared in this scope 34 | void add(ll x,ll d) | ^~ a.cc:34:15: error: 'll' was not declared in this scope 34 | void add(ll x,ll d) | ^~ a.cc:43:1: error: 'll' does not name a type 43 | ll sum(ll x) | ^~ a.cc: In function 'int main()': a.cc:56:5: error: 'll' was not declared in this scope 56 | ll ans=0; | ^~ a.cc:57:23: error: 'n' was not declared in this scope; did you mean 'yn'? 57 | scanf("%lld%lld",&n,&k); | ^ | yn a.cc:57:26: error: 'k' was not declared in this scope 57 | scanf("%lld%lld",&n,&k); | ^ a.cc:60:28: error: 'struct node' has no member named 'value' 60 | scanf("%lld",&a[i].value); | ^~~~~ a.cc:61:14: error: 'struct node' has no member named 'index' 61 | a[i].index=i; | ^~~~~ a.cc:62:14: error: 'struct node' has no member named 'value' 62 | a[i].value-=k; | ^~~~~ a.cc:65:14: error: 'struct node' has no member named 'value' 65 | a[i].value=a[i-1].value+a[i].value; | ^~~~~ a.cc:65:27: error: 'struct node' has no member named 'value' 65 | a[i].value=a[i-1].value+a[i].value; | ^~~~~ a.cc:65:38: error: 'struct node' has no member named 'value' 65 | a[i].value=a[i-1].value+a[i].value; | ^~~~~ a.cc:67:17: error: 'struct node' has no member named 'value' 67 | if(a[i].value>=0) | ^~~~~ a.cc:68:13: error: 'ans' was not declared in this scope; did you mean 'abs'? 68 | ans+=1; | ^~~ | abs a.cc:72:14: error: 'struct node' has no member named 'value' 72 | a[i].value=i; | ^~~~~ a.cc:80:11: error: expected ';' before 'x' 80 | ll x=a[i].value; | ^~ | ; a.cc:81:9: error: 'ans' was not declared in this scope; did you mean 'abs'? 81 | ans+=sum(x); | ^~~ | abs a.cc:81:18: error: 'x' was not declared in this scope 81 | ans+=sum(x); | ^ a.cc:81:14: error: 'sum' was not declared in this scope 81 | ans+=sum(x); | ^~~ a.cc:82:9: error: 'add' was not declared in this scope; did you mean 'fadd'? 82 | add(x,1); | ^~~ | fadd a.cc:84:21: error: 'ans' was not declared in this scope; did you mean 'abs'? 84 | printf("%lld\n",ans); | ^~~ | abs
s133634543
p03703
C++
#include <bits/stdc++.h> #define show(x) cout << #x << " = " << x << endl using namespace std; using ll = long long; using pii = pair<int, int>; using vi = vector<int>; template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "sz=" << v.size() << "\n["; for (const auto& p : v) { os << p << ","; } os << "]\n"; return os; } template <typename S, typename T> ostream& operator<<(ostream& os, const pair<S, T>& p) { os << "(" << p.first << "," << p.second << ")"; return os; } constexpr ll MOD = 1e9 + 7; template <typename T> constexpr T INF = numeric_limits<T>::max() / 100; template <typename Base> class BinaryIndexedTree { public: using T = typename Base::T; using AbelGroup = Base; BinaryIndexedTree(const int n) : data_num(n), size(1 << (__lg(2 * data_num - 1))), value(size + 1, AbelGroup::identity()) { assert(n > 0); } BinaryIndexedTree(const vector<T>& val) : data_num(val.size()), size(1 << (__lg(2 * data_num - 1))), value(size + 1, AbelGroup::identity()) { for (int i = 1; i <= size; i++) { value[i] = val[i - 1]; } for (int x = 1; x < size; x++) { value[x + (x & -x)] += value[x]; } } T accumulate(const int a) const { assert(0 <= a and a < data_num); int ind = a + 1; T sum = AbelGroup::identity(); while (ind > 0) { sum = op(sum, value[ind]); ind &= ind - 1; } return sum; } void add(const int a, const T& val) { assert(0 <= a and a < data_num); int ind = a + 1; while (ind <= size) { value[ind] = op(value[ind], val); ind += ind & (-ind); } } T get(const int a) const { assert(0 <= a and a < data_num); if (a == 0) { return accumulate(a); } else { return op(op.inv(accumulate(a - 1)), accumulate(a)); } } void print() const { show(value); } // Needs ordered in Base abel-group int lowerBound(T w) const { if (w <= AbelGroup::identity()) { return 0; } int x = 0; for (int k = ((size == data_num) ? size : size / 2); k > 0; k /= 2) { if (x + k <= size and value[x + k] < w) { w = op(w, op.inv(value[x + k])); x += k; } } return x; } private: const int data_num; const int size; const AbelGroup op{}; vector<T> value; }; struct Sum { using T = ll; T operator()(const T& a, const T& b) const { return a + b; } T inv(const T& a) const { return -a; } static constexpr T identity() { return 0; } }; int main() { int n, k; cin >> n >> k; vector<ll> a(n); vector<ll> s(n); for (ll i = 0; i < n; i++) { cin >> a[i]; if (i == 0) { s[i] = a[i]; } else { s[i] = s[i - 1] + a[i]; } } vector<ll> t(n); for (ll i = 0; i < n; i++) { t[i] = s[i] - (i + 1) * k; } int un = 0; for (ll i = 0; i < n; i++) { if (t[i] >= 0) { un++; } } // show(t); map<int, int> zip; vector<ll> t_copy = t; sort(t_copy.begin(), t_copy.end()); t_copy.erase(unique(t_copy.begin(), t_copy.end()), t_copy.end()); for (int i = 0; i < t_copy.size(); i++) { zip[t_copy[i]] = i; } for (int i = 0; i < n; i++) { t[i] = zip[t[i]]; } // show(t); BinaryIndexedTree<Sum> bit{n}; ll sum = 0; for (int i = 0; i < n; i++) { // bit.print(); sum += bit.accumulate(t[i]); bit.add(t[i], 1); } // bit.print(); cout << sum + un << endl; return 0; } #include <bits/stdc++.h> #define show(x) cout << #x << " = " << x << endl using namespace std; using ll = long long; using pii = pair<int, int>; using vi = vector<int>; template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "sz=" << v.size() << "\n["; for (const auto& p : v) { os << p << ","; } os << "]\n"; return os; } template <typename S, typename T> ostream& operator<<(ostream& os, const pair<S, T>& p) { os << "(" << p.first << "," << p.second << ")"; return os; } constexpr ll MOD = 1e9 + 7; template <typename T> constexpr T INF = numeric_limits<T>::max() / 100; template <typename Base> class BinaryIndexedTree { public: using T = typename Base::T; using AbelGroup = Base; BinaryIndexedTree(const int n) : data_num(n), size(1 << (__lg(2 * data_num - 1))), value(size + 1, AbelGroup::identity()) { assert(n > 0); } BinaryIndexedTree(const vector<T>& val) : data_num(val.size()), size(1 << (__lg(2 * data_num - 1))), value(size + 1, AbelGroup::identity()) { for (int i = 1; i <= size; i++) { value[i] = val[i - 1]; } for (int x = 1; x < size; x++) { value[x + (x & -x)] += value[x]; } } T accumulate(const int a) const { assert(0 <= a and a < data_num); int ind = a + 1; T sum = AbelGroup::identity(); while (ind > 0) { sum = op(sum, value[ind]); ind &= ind - 1; } return sum; } void add(const int a, const T& val) { assert(0 <= a and a < data_num); int ind = a + 1; while (ind <= size) { value[ind] = op(value[ind], val); ind += ind & (-ind); } } T get(const int a) const { assert(0 <= a and a < data_num); if (a == 0) { return accumulate(a); } else { return op(op.inv(accumulate(a - 1)), accumulate(a)); } } void print() const { show(value); } // Needs ordered in Base abel-group int lowerBound(T w) const { if (w <= AbelGroup::identity()) { return 0; } int x = 0; for (int k = ((size == data_num) ? size : size / 2); k > 0; k /= 2) { if (x + k <= size and value[x + k] < w) { w = op(w, op.inv(value[x + k])); x += k; } } return x; } private: const int data_num; const int size; const AbelGroup op{}; vector<T> value; }; struct Sum { using T = ll; T operator()(const T& a, const T& b) const { return a + b; } T inv(const T& a) const { return -a; } static constexpr T identity() { return 0; } }; int main() { int n, k; cin >> n >> k; vector<ll> a(n); vector<ll> s(n); for (ll i = 0; i < n; i++) { cin >> a[i]; if (i == 0) { s[i] = a[i]; } else { s[i] = s[i - 1] + a[i]; } } vector<ll> t(n); for (ll i = 0; i < n; i++) { t[i] = s[i] - (i + 1) * k; } int un = 0; for (ll i = 0; i < n; i++) { if (t[i] >= 0) { un++; } } // show(t); map<int, int> zip; vector<ll> t_copy = t; sort(t_copy.begin(), t_copy.end()); t_copy.erase(unique(t_copy.begin(), t_copy.end()), t_copy.end()); for (int i = 0; i < t_copy.size(); i++) { zip[t_copy[i]] = i; } for (int i = 0; i < n; i++) { t[i] = zip[t[i]]; } // show(t); BinaryIndexedTree<Sum> bit{n}; ll sum = 0; for (int i = 0; i < n; i++) { // bit.print(); sum += bit.accumulate(t[i]); bit.add(t[i], 1); } // bit.print(); cout << sum + un << endl; return 0; } #include <bits/stdc++.h> #define show(x) cout << #x << " = " << x << endl using namespace std; using ll = long long; using pii = pair<int, int>; using vi = vector<int>; template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "sz=" << v.size() << "\n["; for (const auto& p : v) { os << p << ","; } os << "]\n"; return os; } template <typename S, typename T> ostream& operator<<(ostream& os, const pair<S, T>& p) { os << "(" << p.first << "," << p.second << ")"; return os; } constexpr ll MOD = 1e9 + 7; template <typename T> constexpr T INF = numeric_limits<T>::max() / 100; template <typename Base> class BinaryIndexedTree { public: using T = typename Base::T; using AbelGroup = Base; BinaryIndexedTree(const int n) : data_num(n), size(1 << (__lg(2 * data_num - 1))), value(size + 1, AbelGroup::identity()) { assert(n > 0); } BinaryIndexedTree(const vector<T>& val) : data_num(val.size()), size(1 << (__lg(2 * data_num - 1))), value(size + 1, AbelGroup::identity()) { for (int i = 1; i <= size; i++) { value[i] = val[i - 1]; } for (int x = 1; x < size; x++) { value[x + (x & -x)] += value[x]; } } T accumulate(const int a) const { assert(0 <= a and a < data_num); int ind = a + 1; T sum = AbelGroup::identity(); while (ind > 0) { sum = op(sum, value[ind]); ind &= ind - 1; } return sum; } void add(const int a, const T& val) { assert(0 <= a and a < data_num); int ind = a + 1; while (ind <= size) { value[ind] = op(value[ind], val); ind += ind & (-ind); } } T get(const int a) const { assert(0 <= a and a < data_num); if (a == 0) { return accumulate(a); } else { return op(op.inv(accumulate(a - 1)), accumulate(a)); } } void print() const { show(value); } // Needs ordered in Base abel-group int lowerBound(T w) const { if (w <= AbelGroup::identity()) { return 0; } int x = 0; for (int k = ((size == data_num) ? size : size / 2); k > 0; k /= 2) { if (x + k <= size and value[x + k] < w) { w = op(w, op.inv(value[x + k])); x += k; } } return x; } private: const int data_num; const int size; const AbelGroup op{}; vector<T> value; }; struct Sum { using T = ll; T operator()(const T& a, const T& b) const { return a + b; } T inv(const T& a) const { return -a; } static constexpr T identity() { return 0; } }; int main() { int n, k; cin >> n >> k; vector<ll> a(n); vector<ll> s(n); for (ll i = 0; i < n; i++) { cin >> a[i]; if (i == 0) { s[i] = a[i]; } else { s[i] = s[i - 1] + a[i]; } } vector<ll> t(n); for (ll i = 0; i < n; i++) { t[i] = s[i] - (i + 1) * k; } int un = 0; for (ll i = 0; i < n; i++) { if (t[i] >= 0) { un++; } } // show(t); map<int, int> zip; vector<ll> t_copy = t; sort(t_copy.begin(), t_copy.end()); t_copy.erase(unique(t_copy.begin(), t_copy.end()), t_copy.end()); for (int i = 0; i < t_copy.size(); i++) { zip[t_copy[i]] = i; } for (int i = 0; i < n; i++) { t[i] = zip[t[i]]; } // show(t); BinaryIndexedTree<Sum> bit{n}; ll sum = 0; for (int i = 0; i < n; i++) { // bit.print(); sum += bit.accumulate(t[i]); bit.add(t[i], 1); } // bit.print(); cout << sum + un << endl; return 0; } #include <bits/stdc++.h> #define show(x) cout << #x << " = " << x << endl using namespace std; using ll = long long; using pii = pair<int, int>; using vi = vector<int>; template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "sz=" << v.size() << "\n["; for (const auto& p : v) { os << p << ","; } os << "]\n"; return os; } template <typename S, typename T> ostream& operator<<(ostream& os, const pair<S, T>& p) { os << "(" << p.first << "," << p.second << ")"; return os; } constexpr ll MOD = 1e9 + 7; template <typename T> constexpr T INF = numeric_limits<T>::max() / 100; template <typename Base> class BinaryIndexedTree { public: using T = typename Base::T; using AbelGroup = Base; BinaryIndexedTree(const int n) : data_num(n), size(1 << (__lg(2 * data_num - 1))), value(size + 1, AbelGroup::identity()) { assert(n > 0); } BinaryIndexedTree(const vector<T>& val) : data_num(val.size()), size(1 << (__lg(2 * data_num - 1))), value(size + 1, AbelGroup::identity()) { for (int i = 1; i <= size; i++) { value[i] = val[i - 1]; } for (int x = 1; x < size; x++) { value[x + (x & -x)] += value[x]; } } T accumulate(const int a) const { assert(0 <= a and a < data_num); int ind = a + 1; T sum = AbelGroup::identity(); while (ind > 0) { sum = op(sum, value[ind]); ind &= ind - 1; } return sum; } void add(const int a, const T& val) { assert(0 <= a and a < data_num); int ind = a + 1; while (ind <= size) { value[ind] = op(value[ind], val); ind += ind & (-ind); } } T get(const int a) const { assert(0 <= a and a < data_num); if (a == 0) { return accumulate(a); } else { return op(op.inv(accumulate(a - 1)), accumulate(a)); } } void print() const { show(value); } // Needs ordered in Base abel-group int lowerBound(T w) const { if (w <= AbelGroup::identity()) { return 0; } int x = 0; for (int k = ((size == data_num) ? size : size / 2); k > 0; k /= 2) { if (x + k <= size and value[x + k] < w) { w = op(w, op.inv(value[x + k])); x += k; } } return x; } private: const int data_num; const int size; const AbelGroup op{}; vector<T> value; }; struct Sum { using T = ll; T operator()(const T& a, const T& b) const { return a + b; } T inv(const T& a) const { return -a; } static constexpr T identity() { return 0; } }; int main() { int n, k; cin >> n >> k; vector<ll> a(n); vector<ll> s(n); for (ll i = 0; i < n; i++) { cin >> a[i]; if (i == 0) { s[i] = a[i]; } else { s[i] = s[i - 1] + a[i]; } } vector<ll> t(n); for (ll i = 0; i < n; i++) { t[i] = s[i] - (i + 1) * k; } int un = 0; for (ll i = 0; i < n; i++) { if (t[i] >= 0) { un++; } } // show(t); map<int, int> zip; vector<ll> t_copy = t; sort(t_copy.begin(), t_copy.end()); t_copy.erase(unique(t_copy.begin(), t_copy.end()), t_copy.end()); for (int i = 0; i < t_copy.size(); i++) { zip[t_copy[i]] = i; } for (int i = 0; i < n; i++) { t[i] = zip[t[i]]; } // show(t); BinaryIndexedTree<Sum> bit{n}; ll sum = 0; for (int i = 0; i < n; i++) { // bit.print(); sum += bit.accumulate(t[i]); bit.add(t[i], 1); } // bit.print(); cout << sum + un << endl; return 0; }
a.cc:188:10: error: redefinition of 'template<class T> std::ostream& operator<<(std::ostream&, const std::vector<_Tp>&)' 188 | ostream& operator<<(ostream& os, const vector<T>& v) | ^~~~~~~~ a.cc:11:10: note: 'template<class T> std::ostream& operator<<(std::ostream&, const std::vector<_Tp>&)' previously declared here 11 | ostream& operator<<(ostream& os, const vector<T>& v) | ^~~~~~~~ a.cc:199:10: error: redefinition of 'template<class S, class T> std::ostream& operator<<(std::ostream&, const std::pair<_T1, _T2>&)' 199 | ostream& operator<<(ostream& os, const pair<S, T>& p) | ^~~~~~~~ a.cc:22:10: note: 'template<class S, class T> std::ostream& operator<<(std::ostream&, const std::pair<_T1, _T2>&)' previously declared here 22 | ostream& operator<<(ostream& os, const pair<S, T>& p) | ^~~~~~~~ a.cc:207:14: error: redefinition of 'constexpr const ll MOD' 207 | constexpr ll MOD = 1e9 + 7; | ^~~ a.cc:30:14: note: 'constexpr const ll MOD' previously defined here 30 | constexpr ll MOD = 1e9 + 7; | ^~~ a.cc:210:13: error: redefinition of 'template<class T> constexpr const T INF' 210 | constexpr T INF = numeric_limits<T>::max() / 100; | ^~~ a.cc:33:13: note: 'template<class T> constexpr const T INF<T>' previously declared here 33 | constexpr T INF = numeric_limits<T>::max() / 100; | ^~~ a.cc:213:7: error: redefinition of 'class BinaryIndexedTree<Base>' 213 | class BinaryIndexedTree | ^~~~~~~~~~~~~~~~~ a.cc:36:7: note: previous definition of 'class BinaryIndexedTree<Base>' 36 | class BinaryIndexedTree | ^~~~~~~~~~~~~~~~~ a.cc:290:8: error: redefinition of 'struct Sum' 290 | struct Sum { | ^~~ a.cc:113:8: note: previous definition of 'struct Sum' 113 | struct Sum { | ^~~ a.cc:306:5: error: redefinition of 'int main()' 306 | int main() | ^~~~ a.cc:129:5: note: 'int main()' previously defined here 129 | int main() | ^~~~ a.cc:365:10: error: redefinition of 'template<class T> std::ostream& operator<<(std::ostream&, const std::vector<_Tp>&)' 365 | ostream& operator<<(ostream& os, const vector<T>& v) | ^~~~~~~~ a.cc:11:10: note: 'template<class T> std::ostream& operator<<(std::ostream&, const std::vector<_Tp>&)' previously declared here 11 | ostream& operator<<(ostream& os, const vector<T>& v) | ^~~~~~~~ a.cc:376:10: error: redefinition of 'template<class S, class T> std::ostream& operator<<(std::ostream&, const std::pair<_T1, _T2>&)' 376 | ostream& operator<<(ostream& os, const pair<S, T>& p) | ^~~~~~~~ a.cc:22:10: note: 'template<class S, class T> std::ostream& operator<<(std::ostream&, const std::pair<_T1, _T2>&)' previously declared here 22 | ostream& operator<<(ostream& os, const pair<S, T>& p) | ^~~~~~~~ a.cc:384:14: error: redefinition of 'constexpr const ll MOD' 384 | constexpr ll MOD = 1e9 + 7; | ^~~ a.cc:30:14: note: 'constexpr const ll MOD' previously defined here 30 | constexpr ll MOD = 1e9 + 7; | ^~~ a.cc:387:13: error: redefinition of 'template<class T> constexpr const T INF' 387 | constexpr T INF = numeric_limits<T>::max() / 100; | ^~~ a.cc:33:13: note: 'template<class T> constexpr const T INF<T>' previously declared here 33 | constexpr T INF = numeric_limits<T>::max() / 100; | ^~~ a.cc:390:7: error: redefinition of 'class BinaryIndexedTree<Base>' 390 | class BinaryIndexedTree | ^~~~~~~~~~~~~~~~~ a.cc:36:7: note: previous definition of 'class BinaryIndexedTree<Base>' 36 | class BinaryIndexedTree | ^~~~~~~~~~~~~~~~~ a.cc:467:8: error: redefinition of 'struct Sum' 467 | struct Sum { | ^~~ a.cc:113:8: note: previous definition of 'struct Sum' 113 | struct Sum { | ^~~ a.cc:483:5: error: redefinition of 'int main()' 483 | int main() | ^~~~ a.cc:129:5: note: 'int main()' previously defined here 129 | int main() | ^~~~ a.cc:542:10: error: redefinition of 'template<class T> std::ostream& operator<<(std::ostream&, const std::vector<_Tp>&)' 542 | ostream& operator<<(ostream& os, const vector<T>& v) | ^~~~~~~~ a.cc:11:10: note: 'template<class T> std::ostream& operator<<(std::ostream&, const std::vector<_Tp>&)' previously declared here 11 | ostream& operator<<(ostream& os, const vector<T>& v) | ^~~~~~~~ a.cc:553:10: error: redefinition of 'template<class S, class T> std::ostream& operator<<(std::ostream&, const std::pair<_T1, _T2>&)' 553 | ostream& operator<<(ostream& os, const pair<S, T>& p) | ^~~~~~~~ a.cc:22:10: note: 'template<class S, class T> std::ostream& operator<<(std::ostream&, const std::pair<_T1, _T2>&)' previously declared here 22 | ostream& operator<<(ostream& os, const pair<S, T>& p) | ^~~~~~~~ a.cc:561:14: error: redefinition of 'constexpr const ll MOD' 561 | constexpr ll MOD = 1e9 + 7; | ^~~ a.cc:30:14: note: 'constexpr const ll MOD' previously defined here 30 | constexpr ll MOD = 1e9 + 7; | ^~~ a.cc:564:13: error: redefinition of 'template<class T> constexpr const T INF' 564 | constexpr T INF = numeric_limits<T>::max() / 100; | ^~~ a.cc:33:13: note: 'template<class T> constexpr const T INF<T>' previously declared here 33 | constexpr T INF = numeric_limits<T>::max() / 100; | ^~~ a.cc:567:7: error: redefinition of 'class BinaryIndexedTree<Base>' 567 | class BinaryIndexedTree | ^~~~~~~~~~~~~~~~~ a.cc:36:7: note: previous definition of 'class BinaryIndexedTree<Base>' 36 | class BinaryIndexedTree | ^~~~~~~~~~~~~~~~~ a.cc:644:8: error: redefinition of 'struct Sum' 644 | struct Sum { | ^~~ a.cc:113:8: note: previous definition of 'struct Sum' 113 | struct Sum { | ^~~ a.cc:660:5: error: redefinition of 'int main()' 660 | int main() | ^~~~ a.cc:129:5: note: 'int main()' previously defined here 129 | int main() | ^~~~
s347854816
p03703
C++
#include<stdio.h> #include<iostream> #include<stdlib.h> #include<string.h> #include<algorithm> #include<vector> #include<math.h> #include<queue> #include<stack> #include<map> using namespace std; const int size=2e6+10; const int INF=1e9; typedef long long LL; //LL tree[size]; LL a[size]; LL b[size]; //int lowbit(int x) //{ // return x&(-x); //} //void update(int x) //{ // while(x<size) // { // tree[x]+=1; // x+=lowbit(x); // } //} //LL ask(int x) //{ // LL sum=0; // while(x) // { // sum+=tree[x]; // x-=lowbit(x); // } // return sum; //} struct node { int l,r; LL sum; }tree[size]; //void build(int l,int r,int rt) //{ // int mid=(l+r)>>1; // tree[rt].l=l,tree[rt].r=r,tree[rt].sum=0; // if(l==r) return ; // build(l,mid,rt*2); // build(mid+1,r,rt*2+1); //} void pushdown(int rt) { tree[rt].sum=tree[rt*2].sum+tree[rt*2+1].sum; } void update(int pos,int l,int r,int rt) { if(l==r) { tree[rt].sum++; return ; } int mid=(l+r)>>1; if(pos<=mid) update(pos,l,mid,rt*2); else update(pos,mid+1,r,rt*2+1); pushdown(rt); } LL ask(int l,int r,int rt) { if(l>r) return 0; if(l>=tree[rt].l&&r>=tree[rt].r) return tree[rt].sum; LL sum=0; int mid=(l+r)>>1; if(l<=mid) sum+=ask(l,mid,rt*2); if(r>mid) sum+=ask(mid+1,r,rt*2+1); return sum; } int main() { int n;LL p; while(scanf("%d%lld",&n,&p)!=EOF) { memset(tree,0,sizeof(tree)); build(1,n+1,1); LL ans=0; for(int i=1;i<=n;i++) scanf("%lld",&b[i]); for(int i=1;i<=n;i++) { b[i]-=p; b[i]=b[i]+b[i-1]; if(b[i]>=0) ans++; a[i-1]=b[i]; } sort(a,a+n); int cnt=unique(a,a+n)-a; build(1,n,1); for(int i=1;i<=n;i++) { int temp=lower_bound(a,a+cnt,b[i])-a+1; LL pri=ask(1,temp+1,1); ans+=pri; // printf("pri=%d\n",pri); update(temp,1,n,1); } // out(1,n,1); printf("%lld\n",ans); } }
a.cc:16:6: error: reference to 'size' is ambiguous 16 | LL a[size]; | ^~~~ In file included from /usr/include/c++/14/string:53, from /usr/include/c++/14/bits/locale_classes.h:40, from /usr/include/c++/14/bits/ios_base.h:41, from /usr/include/c++/14/ios:44, from /usr/include/c++/14/ostream:40, from /usr/include/c++/14/iostream:41, from a.cc:2: /usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])' 272 | size(const _Tp (&)[_Nm]) noexcept | ^~~~ /usr/include/c++/14/bits/range_access.h:262:5: note: 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)' 262 | size(const _Container& __cont) noexcept(noexcept(__cont.size())) | ^~~~ a.cc:12:11: note: 'const int size' 12 | const int size=2e6+10; | ^~~~ a.cc:17:6: error: reference to 'size' is ambiguous 17 | LL b[size]; | ^~~~ /usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])' 272 | size(const _Tp (&)[_Nm]) noexcept | ^~~~ /usr/include/c++/14/bits/range_access.h:262:5: note: 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)' 262 | size(const _Container& __cont) noexcept(noexcept(__cont.size())) | ^~~~ a.cc:12:11: note: 'const int size' 12 | const int size=2e6+10; | ^~~~ a.cc:44:7: error: reference to 'size' is ambiguous 44 | }tree[size]; | ^~~~ /usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])' 272 | size(const _Tp (&)[_Nm]) noexcept | ^~~~ /usr/include/c++/14/bits/range_access.h:262:5: note: 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)' 262 | size(const _Container& __cont) noexcept(noexcept(__cont.size())) | ^~~~ a.cc:12:11: note: 'const int size' 12 | const int size=2e6+10; | ^~~~ a.cc: In function 'void pushdown(int)': a.cc:55:5: error: 'tree' was not declared in this scope; did you mean 'free'? 55 | tree[rt].sum=tree[rt*2].sum+tree[rt*2+1].sum; | ^~~~ | free a.cc: In function 'void update(int, int, int, int)': a.cc:61:9: error: 'tree' was not declared in this scope; did you mean 'free'? 61 | tree[rt].sum++; return ; | ^~~~ | free a.cc: In function 'LL ask(int, int, int)': a.cc:71:11: error: 'tree' was not declared in this scope; did you mean 'free'? 71 | if(l>=tree[rt].l&&r>=tree[rt].r) | ^~~~ | free a.cc: In function 'int main()': a.cc:84:15: error: 'tree' was not declared in this scope; did you mean 'free'? 84 | memset(tree,0,sizeof(tree)); | ^~~~ | free a.cc:85:6: error: 'build' was not declared in this scope 85 | build(1,n+1,1); | ^~~~~ a.cc:87:42: error: 'b' was not declared in this scope 87 | for(int i=1;i<=n;i++) scanf("%lld",&b[i]); | ^ a.cc:90:10: error: 'b' was not declared in this scope 90 | b[i]-=p; | ^ a.cc:93:10: error: 'a' was not declared in this scope 93 | a[i-1]=b[i]; | ^ a.cc:95:11: error: 'a' was not declared in this scope 95 | sort(a,a+n); | ^ a.cc:100:40: error: 'b' was not declared in this scope 100 | int temp=lower_bound(a,a+cnt,b[i])-a+1; | ^
s098932344
p03703
C++
#include <bits/stdc++.h> using namespace std; const int size=1e5+10; const int INF=1e9; int tree[size]; int a[size]; typedef long long LL; int lowbit(int x) { return x&(-x); } void update(int x) { while(x<size) { tree[x]+=1; x+=lowbit(x); } } int ask(int x) { int sum=0; while(x) { sum+=tree[x]; x-=lowbit(x); } return sum; } LL b[size]; int main() { int T; scanf("%d",&T); while(T--) { memset(tree,0,sizeof(tree)); LL p,ans=0;int n; scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%lld",&b[i]); } scanf("%lld",&p); for(int i=1;i<=n;i++) { b[i]-=p; // b[i]=b[i]+b[i-1]; if(b[i]>=0) ans++; a[i-1]=b[i]; } sort(a,a+n); int cnt=unique(a,a+n)-a; int temp=lower_bound(a,a+cnt,b[1])-a+n;; update(temp); for(int i=2;i<=n;i++) { temp=lower_bound(a,a+cnt,b[i])-a+n; ans+=ask(temp); update(temp); } printf("%lld\n",ans); // printf("%d\n",) // for(int i=0;i<cnt;i++) // printf("%d ",a[i]); // printf("%d\n",ans); } }
a.cc:5:10: error: reference to 'size' is ambiguous 5 | int tree[size]; | ^~~~ In file included from /usr/include/c++/14/string:53, from /usr/include/c++/14/bitset:52, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52, from a.cc:1: /usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])' 272 | size(const _Tp (&)[_Nm]) noexcept | ^~~~ /usr/include/c++/14/bits/range_access.h:262:5: note: 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)' 262 | size(const _Container& __cont) noexcept(noexcept(__cont.size())) | ^~~~ a.cc:3:11: note: 'const int size' 3 | const int size=1e5+10; | ^~~~ a.cc:6:7: error: reference to 'size' is ambiguous 6 | int a[size]; | ^~~~ /usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])' 272 | size(const _Tp (&)[_Nm]) noexcept | ^~~~ /usr/include/c++/14/bits/range_access.h:262:5: note: 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)' 262 | size(const _Container& __cont) noexcept(noexcept(__cont.size())) | ^~~~ a.cc:3:11: note: 'const int size' 3 | const int size=1e5+10; | ^~~~ a.cc: In function 'void update(int)': a.cc:14:13: error: reference to 'size' is ambiguous 14 | while(x<size) | ^~~~ /usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])' 272 | size(const _Tp (&)[_Nm]) noexcept | ^~~~ /usr/include/c++/14/bits/range_access.h:262:5: note: 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)' 262 | size(const _Container& __cont) noexcept(noexcept(__cont.size())) | ^~~~ a.cc:3:11: note: 'const int size' 3 | const int size=1e5+10; | ^~~~ a.cc:16:9: error: 'tree' was not declared in this scope; did you mean 'free'? 16 | tree[x]+=1; | ^~~~ | free a.cc: In function 'int ask(int)': a.cc:25:13: error: 'tree' was not declared in this scope; did you mean 'free'? 25 | sum+=tree[x]; | ^~~~ | free a.cc: At global scope: a.cc:30:6: error: reference to 'size' is ambiguous 30 | LL b[size]; | ^~~~ /usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])' 272 | size(const _Tp (&)[_Nm]) noexcept | ^~~~ /usr/include/c++/14/bits/range_access.h:262:5: note: 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)' 262 | size(const _Container& __cont) noexcept(noexcept(__cont.size())) | ^~~~ a.cc:3:11: note: 'const int size' 3 | const int size=1e5+10; | ^~~~ a.cc: In function 'int main()': a.cc:37:15: error: 'tree' was not declared in this scope; did you mean 'free'? 37 | memset(tree,0,sizeof(tree)); | ^~~~ | free a.cc:41:24: error: 'b' was not declared in this scope 41 | scanf("%lld",&b[i]); | ^ a.cc:46:11: error: 'b' was not declared in this scope 46 | b[i]-=p; | ^ a.cc:49:10: error: 'a' was not declared in this scope 49 | a[i-1]=b[i]; | ^ a.cc:52:11: error: 'a' was not declared in this scope 52 | sort(a,a+n); | ^ a.cc:54:35: error: 'b' was not declared in this scope 54 | int temp=lower_bound(a,a+cnt,b[1])-a+n;; | ^
s654060820
p03703
Java
import java.util.*; public class TaskE { // Main public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); long k = scanner.nextLong(); long[] a = new long[n]; for(int i = 0; i < n; i ++) { a[i] = scanner.nextLong() - k; } long[] sum = new long[n]; int count = 0; for(int i = 0; i < n; i ++) { sum[i] = a[i]; if(sum[i] >= 0) { count ++; } for(int j = i + 1; j < n; j ++) { sum[j] = sum[j-1] + a[j]; if(sum[j] >= 0) { count ++; } } } System.out.println(count); scanner.close(); } }
Main.java:3: error: class TaskE is public, should be declared in a file named TaskE.java public class TaskE { // Main ^ 1 error
s000297724
p03703
C++
#include<iostream> using namespace std; int main() { int n=0,k=0,r=0; int a[2*(10^5)]; cin >> n >> k; } cout << r << endl; return 0; }
a.cc: In function 'int main()': a.cc:6:20: warning: result of '10^5' is 15; did you mean '1e5'? [-Wxor-used-as-pow] 6 | int a[2*(10^5)]; | ^ | --- | 1e a.cc:6:18: note: you can silence this warning by using a hexadecimal constant (0xa rather than 10) 6 | int a[2*(10^5)]; | ^~ | 0xa a.cc: At global scope: a.cc:10:9: error: 'cout' does not name a type 10 | cout << r << endl; | ^~~~ a.cc:11:9: error: expected unqualified-id before 'return' 11 | return 0; | ^~~~~~ a.cc:13:1: error: expected declaration before '}' token 13 | } | ^
s062092106
p03703
C++
#include<iostream> using namespace std; int main() { int n=0,k=0,r=0; int a[2e50]; cin >> n>>k; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; ++i) { int z = 0; for (int j = i; j < n; ++j) { z += a[j]; if (z / (j+1-i) >= k) { ++r; } } } cout << r << endl; return 0; }
a.cc: In function 'int main()': a.cc:6:15: error: conversion from 'double' to 'long unsigned int' in a converted constant expression 6 | int a[2e50]; | ^~~~ a.cc:6:15: error: could not convert '2.0000000000000002e+50' from 'double' to 'long unsigned int' 6 | int a[2e50]; | ^~~~ | | | double a.cc:6:15: error: size of array 'a' has non-integral type 'double'
s681734472
p03703
C++
#include<iostream> using namespace std; int main() { int n=0,k=0,r=0; int a[2*10^50]; cin >> n; cin >> k; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; ++i) { int z = 0; for (int j = i; j < n; ++j) { z += a[j]; r++ } } cout << r << endl; }
a.cc: In function 'int main()': a.cc:19:28: error: expected ';' before '}' token 19 | r++ | ^ | ; 20 | 21 | } | ~
s762851169
p03703
C++
int main(){ while(){}}
a.cc: In function 'int main()': a.cc:2:7: error: expected primary-expression before ')' token 2 | while(){}} | ^
s429228279
p03703
C
#include <bits/stdc++.h> #include <sys/time.h> using namespace std; #define rep(i,n) for(long long i = 0; i < (long long)(n); i++) #define repi(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++) #define pb push_back #define all(x) (x).begin(), (x).end() #define fi first #define se second #define mt make_tuple #define mp make_pair template<class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); } template<class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } #define exists find_if #define forall all_of using ll = long long; using vll = vector<ll>; using vvll = vector<vll>; using P = pair<ll, ll>; using ld = long double; using vld = vector<ld>; using vi = vector<int>; using vvi = vector<vi>; vll conv(vi& v) { vll r(v.size()); rep(i, v.size()) r[i] = v[i]; return r; } using Pos = complex<double>; template <typename T, typename U> ostream &operator<<(ostream &o, const pair<T, U> &v) { o << "(" << v.first << ", " << v.second << ")"; return o; } template<size_t...> struct seq{}; template<size_t N, size_t... Is> struct gen_seq : gen_seq<N-1, N-1, Is...>{}; template<size_t... Is> struct gen_seq<0, Is...> : seq<Is...>{}; template<class Ch, class Tr, class Tuple, size_t... Is> void print_tuple(basic_ostream<Ch,Tr>& os, Tuple const& t, seq<Is...>){ using s = int[]; (void)s{0, (void(os << (Is == 0? "" : ", ") << get<Is>(t)), 0)...}; } template<class Ch, class Tr, class... Args> auto operator<<(basic_ostream<Ch, Tr>& os, tuple<Args...> const& t) -> basic_ostream<Ch, Tr>& { os << "("; print_tuple(os, t, gen_seq<sizeof...(Args)>()); return os << ")"; } ostream &operator<<(ostream &o, const vvll &v) { rep(i, v.size()) { rep(j, v[i].size()) o << v[i][j] << " "; o << endl; } return o; } template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { o << '['; rep(i, v.size()) o << v[i] << (i != v.size()-1 ? ", " : ""); o << "]"; return o; } template <typename T> ostream &operator<<(ostream &o, const set<T> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it << (next(it) != m.end() ? ", " : ""); o << "]"; return o; } template <typename T, typename U> ostream &operator<<(ostream &o, const map<T, U> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it << (next(it) != m.end() ? ", " : ""); o << "]"; return o; } template <typename T, typename U, typename V> ostream &operator<<(ostream &o, const unordered_map<T, U, V> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it; o << "]"; return o; } vector<int> range(const int x, const int y) { vector<int> v(y - x + 1); iota(v.begin(), v.end(), x); return v; } template <typename T> istream& operator>>(istream& i, vector<T>& o) { rep(j, o.size()) i >> o[j]; return i;} string bits_to_string(ll input, ll n=64) { string s; rep(i, n) s += '0' + !!(input & (1ll << i)); reverse(all(s)); return s; } template <typename T> unordered_map<T, ll> counter(vector<T> vec){unordered_map<T, ll> ret; for (auto&& x : vec) ret[x]++; return ret;}; string substr(string s, P x) {return s.substr(x.fi, x.se - x.fi); } struct ci : public iterator<forward_iterator_tag, ll> { ll n; ci(const ll n) : n(n) { } bool operator==(const ci& x) { return n == x.n; } bool operator!=(const ci& x) { return !(*this == x); } ci &operator++() { n++; return *this; } ll operator*() const { return n; } }; size_t random_seed; namespace std { using argument_type = P; template<> struct hash<argument_type> { size_t operator()(argument_type const& x) const { size_t seed = random_seed; seed ^= hash<ll>{}(x.fi); seed ^= (hash<ll>{}(x.se) << 1); return seed; } }; }; // hash for various class namespace myhash{ const int Bsizes[]={3,9,13,17,21,25,29,33,37,41,45,49,53,57,61,65,69,73,77,81}; const int xor_nums[]={0x100007d1,0x5ff049c9,0x14560859,0x07087fef,0x3e277d49,0x4dba1f17,0x709c5988,0x05904258,0x1aa71872,0x238819b3,0x7b002bb7,0x1cf91302,0x0012290a,0x1083576b,0x76473e49,0x3d86295b,0x20536814,0x08634f4d,0x115405e8,0x0e6359f2}; const int hash_key=xor_nums[rand()%20]; const int mod_key=xor_nums[rand()%20]; template <typename T> struct myhash{ std::size_t operator()(const T& val) const { return (hash<T>{}(val)%mod_key)^hash_key; } }; }; template <typename T> class uset:public std::unordered_set<T,myhash::myhash<T>> { using SET=std::unordered_set<T,myhash::myhash<T>>; public: uset():SET(){SET::rehash(myhash::Bsizes[rand()%20]);} }; template <typename T,typename U> class umap:public std::unordered_map<T,U,myhash::myhash<T>> { public: using MAP=std::unordered_map<T,U,myhash::myhash<T>>; umap():MAP(){MAP::rehash(myhash::Bsizes[rand()%20]);} }; struct timeval start; double sec() { struct timeval tv; gettimeofday(&tv, NULL); return (tv.tv_sec - start.tv_sec) + (tv.tv_usec - start.tv_usec) * 1e-6; } struct init_{init_(){ gettimeofday(&start, NULL); ios::sync_with_stdio(false); cin.tie(0); srand((unsigned int)time(NULL)); random_seed = RAND_MAX / 2 + rand() / 2; }} init__; static const double EPS = 1e-14; static const long long INF = 1e18; static const long long mo = 1e9+7; #define ldout fixed << setprecision(40) // データ型T, 単位元T0, 可換二項演算子opが与えられた時、 // // 点更新opをO(log n)、0-indexの範囲sum(int j)をO(log n)で実現 // もしopに逆演算が定義できるならば、i-indexの範囲sum(int i, int j)が実現可能。 // 0-indexed, sumは閉区間なので注意!! void printBit(int a) {cout << a << " "; for(; a > 0; a >>= 1) cout << (a & 1); cout << "#bit" << endl;} template <class T> struct fenwick_tree { /**********************/ // 実装箇所 /**********************/ T T0 = 0; T op(T a, T b) { return a + b; } /**********************/ // 実装終わり /**********************/ // xのデータ構造。op=+, invop=1, T=int, T0=0の場合 // iが最右添字な数字列をs[i]として、x[i] = s[i]の総和 (例: i=5, s[i]="45", x[i]=9) // 0123456789ABCDEF // 01234567-------- // 0123----89AB---- // 01--23--89--CD-- // 0-2-4-6-8-A-C-E- int n_org; vector<T> x; fenwick_tree(int n_) { n_org = n_; int n = 1; while (n <= n_) n *= 2; x = vector<T>(n, T0); } // 範囲クエリ: [0, j]のreduceを行う。閉区間に注意 // O(log n) T query(int j) { T S = T0; for (j; j >= 0; j = (j & (j + 1)) - 1) // jは、C->B->7と遷移する。0からCをカバーするための数字列の添字へ飛ぶ S = op(S, x[j]); return S; } // 更新クエリ: #kにaを演算する // O(log n) void update(int k, T a) { for (; k < x.size(); k |= k+1) // kは、C->D->Fと遷移する。Cをカバーする数字列全てに飛ぶ x[k] = op(x[k], a); } // #kにアクセスする // O(log n) T access(int k) { return query(k) - (k ? query(k-1) : 0); } void print(void) { for (int i = 0; i < n_org; i++) cout << access(i) << " "; cout << endl; } void print_raw(void) { for (int i = 0; i < x.size(); i++) cout << x[i] << " "; cout << endl; } }; // 数列aの中で、全ての(i, j)ペア(ただしi<j)のうち、 // a[i] <= a[j]なる個数を数え上げる // // moで割った余りを出力するので注意! // // O(n log n) ll countLR(vll a) { ll n = a.size(); vector<P> ai(n); rep(i, n) { ai[i] = P(a[i], i); } sort(all(ai)); fenwick_tree<ll> c(n); ll ret = 0; rep(i, n) { (ret += c.query(ai[i].se-1)) %= mo; c.update(ai[i].se, 1); } return ret; } int main(void) { ll n, k; cin >> n >> k; vll a(n); cin >> a; vll as(n+1); rep(i, n) as[i+1] = as[i] + a[i]; // cout << as << endl; vll b(n+1); rep(i, n+1) { b[i] = as[i] - k * i; } // cout << b << endl; cout << countLR(b) << endl; return 0; }
main.c:1:10: fatal error: bits/stdc++.h: No such file or directory 1 | #include <bits/stdc++.h> | ^~~~~~~~~~~~~~~ compilation terminated.
s751794179
p03703
C++
#![allow(unused_imports)] use std::io; use std::cmp::*; use std::collections::*; #[allow(dead_code)] const M: i64 = 1e9 as i64 + 7; fn read_line() -> String { let stdin = io::stdin(); let mut buf = String::new(); stdin.read_line(&mut buf).unwrap(); buf } #[allow(dead_code)] fn read<T>() -> T where T: std::str::FromStr, T::Err : std::fmt::Debug { read_line().trim().parse().unwrap() } #[allow(dead_code)] fn readv<T>() -> Vec<T> where T: std::str::FromStr, T::Err : std::fmt::Debug { read_line().split(' ').map(|a| a.trim().parse().unwrap()).collect() } struct SegNode { lc: Option<Box<SegNode>>, rc: Option<Box<SegNode>>, beg: usize, lst: usize, value: i64, } impl SegNode { fn new(b: usize, e: usize) -> SegNode { let piv = (b + e) / 2; let (lc, rc) = if b == piv { (None, None) } else { (Some(Box::new(SegNode::new(b, piv))), Some(Box::new(SegNode::new(piv, e)))) }; SegNode { lc: lc, rc: rc, beg: b, lst: e - 1, value: 0, } } fn get(&self, l: usize, r: usize) -> i64 { if l <= self.beg && self.lst <= r{ #[cfg(local)] println!("{}: {:?}", "(self.beg, self.lst, l, r)", (self.beg, self.lst, l, r, self.value)); self.value } else if r < self.beg || self.lst < l { 0 } else if let (&Some(ref lc), &Some(ref rc)) = (&self.lc, &self.rc) { lc.get(l, r) + rc.get(l, r) } else { //panic -1 } } fn add(&mut self, l: usize, r: usize, num: i64) { if l <= self.beg && self.lst <= r{ self.value += num; #[cfg(local)] println!("{}: {:?}", "num", (self.beg, self.lst, l, r, num, self.value)); } else if r < self.beg || self.lst < l { } else if let (&mut Some(ref mut lc), &mut Some(ref mut rc)) = (&mut self.lc, &mut self.rc) { self.value += num * 1; lc.add(l, r, num); rc.add(l, r, num); } } } struct SegTree { root: SegNode } impl SegTree { fn new(size: usize) -> SegTree { SegTree { root: SegNode::new(0, size), } } fn get(&self, l: usize, r: usize) -> i64 { self.root.get(l, r) } fn add(&mut self, l: usize, r: usize, num: i64) { self.root.add(l, r, num); } } fn main() { let input = readv::<i32>(); let (n, k) = (input[0] as usize, input[1]); let mut aa: VecDeque<_> = (0..n).map(|_| read::<i32>() - k).collect(); aa.push_front(k); let mut cnt = 0; let accs: Vec<_> = aa.into_iter().map(|a| { cnt += a; cnt }).collect(); #[cfg(local)] println!("{}: {:?}", "accs", accs); let mut st = SegTree::new(n); let map = accs.iter().collect::<BTreeSet<_>>() .into_iter().enumerate().map(|(i, num)| (num, i)).collect::<HashMap<_, _>>(); let seq = accs.iter().map(|i| map[i]).collect::<Vec<_>>(); #[cfg(local)] println!("{}: {:?}", "seq", seq); let mut ans = 0i64; for i in seq.into_iter().rev() { ans += st.get(i, n - 1); st.add(i, i, 1); #[cfg(local)] println!("{}: {:?}", "(i, ans)", (i, ans)); } println!("{}", ans); }
a.cc:1:2: error: invalid preprocessing directive #! 1 | #![allow(unused_imports)] | ^ a.cc:5:2: error: invalid preprocessing directive #[ 5 | #[allow(dead_code)] | ^ a.cc:14:2: error: invalid preprocessing directive #[ 14 | #[allow(dead_code)] | ^ a.cc:18:2: error: invalid preprocessing directive #[ 18 | #[allow(dead_code)] | ^ a.cc:48:14: error: invalid preprocessing directive #[ 48 | #[cfg(local)] println!("{}: {:?}", "(self.beg, self.lst, l, r)", (self.beg, self.lst, l, r, self.value)); | ^ a.cc:62:14: error: invalid preprocessing directive #[ 62 | #[cfg(local)] println!("{}: {:?}", "num", (self.beg, self.lst, l, r, num, self.value)); | ^ a.cc:91:32: error: too many decimal points in number 91 | let mut aa: VecDeque<_> = (0..n).map(|_| read::<i32>() - k).collect(); | ^~~~ a.cc:95:6: error: invalid preprocessing directive #[ 95 | #[cfg(local)] println!("{}: {:?}", "accs", accs); | ^ a.cc:100:6: error: invalid preprocessing directive #[ 100 | #[cfg(local)] println!("{}: {:?}", "seq", seq); | ^ a.cc:105:10: error: invalid preprocessing directive #[ 105 | #[cfg(local)] println!("{}: {:?}", "(i, ans)", (i, ans)); | ^ a.cc:2:1: error: 'use' does not name a type 2 | use std::io; | ^~~ a.cc:3:1: error: 'use' does not name a type 3 | use std::cmp::*; | ^~~ a.cc:4:1: error: 'use' does not name a type 4 | use std::collections::*; | ^~~ a.cc:6:8: error: found ':' in nested-name-specifier, expected '::' 6 | const M: i64 = 1e9 as i64 + 7; | ^ | :: a.cc:6:7: error: 'M' does not name a type 6 | const M: i64 = 1e9 as i64 + 7; | ^ a.cc:8:1: error: 'fn' does not name a type 8 | fn read_line() -> String { | ^~ a.cc:15:1: error: 'fn' does not name a type 15 | fn read<T>() -> T where T: std::str::FromStr, T::Err : std::fmt::Debug { | ^~ a.cc:19:1: error: 'fn' does not name a type 19 | fn readv<T>() -> Vec<T> where T: std::str::FromStr, T::Err : std::fmt::Debug { | ^~ a.cc:24:5: error: 'lc' does not name a type 24 | lc: Option<Box<SegNode>>, | ^~ a.cc:30:6: error: expected initializer before 'SegNode' 30 | impl SegNode { | ^~~~~~~ a.cc:72:5: error: 'root' does not name a type 72 | root: SegNode | ^~~~ a.cc:74:6: error: expected initializer before 'SegTree' 74 | impl SegTree { | ^~~~~~~ a.cc:88:1: error: 'fn' does not name a type 88 | fn main() { | ^~
s382818942
p03703
Java
/** * @author Finn Lidbetter */ import java.util.*; import java.io.*; import java.awt.geom.*; public class TaskE { static long[] t; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb = new StringBuilder(); String[] s = br.readLine().split(" "); int n = Integer.parseInt(s[0]); long k = Long.parseLong(s[1]); long[] arr = new long[n]; Pair[] pairs = new Pair[n+1]; long arrSum = 0; for (int i=0; i<n; i++) { arr[i] = Long.parseLong(br.readLine()); arrSum += arr[i]; pairs[i] = new Pair(i, arrSum-(i+1)*k); } pairs[n] = new Pair(-1,0); Arrays.sort(pairs); //System.out.println(Arrays.toString(pairs)); FT1 ft = new FT1(n+1); long sum = 0; for (int i=0; i<n+1; i++) { Pair p = pairs[i]; ft.add(p.index+2, 1); long prev = sum; sum += ft.sum(1,p.index+1); //System.out.println(ft.print()); //System.out.println("Added: "+(sum-prev)+" on insert of: "+p); } System.out.println(sum); } } class Pair implements Comparable<Pair> { int index; long val; Pair(int i, long v) { index = i; val = v; } public int compareTo(Pair p2) { if (val==p2.val) return index-p2.index; return (int)(val-p2.val); } public String toString() { return "["+val+","+index+"]"; } } class FT1 { int[] arr; FT1(int n) { arr = new int[n+1]; } int sum(int i, int j) { return sum(j)-sum(i-1); } int sum(int i) { int sum=0; while (i>0) { sum+=arr[i]; i-=i&-i; } return sum; } void add(int i, int delta) { if (i<=0) return; while(i<arr.length) { arr[i] += delta; i+=i&-i; } } String print() { String[] s = new String[arr.length-1]; for (int i=0; i<s.length; i++) { s[i] = ""+ sum(i+1,i+1); } return String.join(", ",s); } }
Main.java:8: error: class TaskE is public, should be declared in a file named TaskE.java public class TaskE { ^ 1 error
s251258334
p03703
C++
#include <iostream> #include <cstring> #include <cstdio> using namespace std; typedef long long ll; const int M = 2e5 + 10; struct TnT { int pos; ll val; }nn[M]; struct node { int l , r; ll sum; }T[M << 2]; bool cmp(TnT a , TnT b) { if(a.val == b.val) return a.pos < b.pos; return a.val < b.val; } void push_up(int i) { T[i].sum = T[i << 1].sum + T[(i << 1) | 1].sum; } void build(int i , int l , int r) { int mid = (l + r) >> 1; T[i].l = l , T[i].r = r , T[i].sum = 0; if(l == r) return ; build(i << 1 , l , mid); build((i << 1) | 1 , mid + 1 , r); push_up(i); } void update(int i , int pos) { int mid = (T[i].l + T[i].r) >> 1; if(T[i].l == pos && T[i].r == pos) { T[i].sum++; return ; } if(mid < pos) update((i << 1) | 1 , pos); else update(i << 1 , pos); push_up(i); } ll query(int i , int l , int r) { int mid = (T[i].l + T[i].r) >> 1; if(T[i].l == l && T[i].r == r) { return T[i].sum; } push_up(i); if(mid < l) return query((i << 1) | 1 , l , r); else if(mid >= r) return query(i << 1 , l , r); else { return query(i << 1 , l , mid) + query((i << 1) | 1 , mid + 1 , r); } } int main() { ll n , k , a; scanf("%lld%lld" , &n , &k); for(int i = 1 ; i <= n ; i++) { scanf("%lld" , &a); a -= k; nn[i].pos = i; nn[i].val = nn[i - 1].val + a; } sort(nn + 1 , nn + 1 + n , cmp); ll ans = 0; build(1 , 1 , (int)n); for(int i = 1 ; i <= n ; i++) { update(1 , nn[i].pos); if(nn[i].val >= 0) ans++; if(nn[i].pos - 1 == 0) continue; ans += query(1 , 1 , nn[i].pos - 1); } printf("%lld\n" , ans); return 0; }
a.cc: In function 'int main()': a.cc:61:5: error: 'sort' was not declared in this scope; did you mean 'short'? 61 | sort(nn + 1 , nn + 1 + n , cmp); | ^~~~ | short
s483805550
p03703
C++
#include <bits/stdc++.h> using namespace std; #define int long long #define fs first #define se second #define all(v) v.begin(), v.end() #define rep(i, n) for (int i = 0; i < n; ++i) #define pb emplace_back using pii = pair<int, int>; using vi = vector<int>; using lint = long long; const int inf = 1001001001; const lint linf = 1001001001001001001ll; const int mod = 1e9 + 7; const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1}; template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; } return a > b; } template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; } return a < b; } template<typename T> inline void print(const T &x, string s = "\n") { cout << x << s; } template<typename T> inline void print(const vector<T> &v, string s = " ") { rep(i, v.size()) cout << v[i] << (i + 1 == v.size() ? "\n" : s); } inline bool inside(int y, int x, int H, int W) { return 0 <= y && y < H && 0 <= x && x < W; } inline lint in() { lint x; std::cin>>x; return x; } lint n, k; vector<lint> a(1, 0), zip; map<lint, lint> unzip; lint bit[202020]; lint sum(int i) { i++; lint s = 0; while (i > 0) { s += bit[i]; i -= i & -i; } return s; } void add(int i, int x) { i++; while (i <= n) { bit[i] += x; i += i & -i; } } int main() { cin >> n >> k; rep(i, n) a.pb(in() - k); for (int i = 1; i <= n; ++i) { a[i] += a[i - 1]; } for (int i = 0; i <= n; ++i) { zip.pb(a[i]); } sort(all(zip)); zip.erase(unique(all(zip)), zip.end()); for (int i = 0; i < zip.size(); ++i) { unzip[zip[i]] = i; } for (int i = 0; i <= n; ++i) { a[i] = unzip[a[i]]; } lint ans = 0; for (int i = 0; i <= n; ++i) { ans += sum(a[i]); add(a[i], 1); } //print(zip); //print(a); cout << ans << endl; }
cc1plus: error: '::main' must return 'int'
s360967557
p03703
C++
3 6 7 5 7
a.cc:1:1: error: expected unqualified-id before numeric constant 1 | 3 6 | ^
s687808051
p03703
C++
#include <cstdio> #include <algorithm> using namespace std; const int maxn=2e5+10; typedef long long LL; #define x first #define y second int n; LL k; LL a[maxn]; pair<LL,int> sum[maxn]; int rank[maxn]; LL ans,bit[maxn]; int lowbit(int p) { return p&(-p); } LL search(int p) { LL ans=0; while(p>0) { ans+=bit[p]; p-=lowbit(p); } return ans; } void add(int p) { while(p<=n) { bit[p]++; p+=lowbit(p); } return; } int main() { scanf("%d%lld",&n,&k); ans=0; for(int i=1;i<=n;i++) { scanf("%lld",a[i]); a[i]-=k; sum[i].x=sum[i-1].x+a[i]; sum[i].y=i; if (sum[i].x>0) ans++; } sort(sum+1,sum+n+1); for(int i=1;i<=n;i++) rank[sum[i].y]=i; for(int i=1;i<=n;i++) { ans+=search(rank[i]-1); add(rank[i]); } printf("%lld\n",ans); return 0; }
a.cc: In function 'int main()': a.cc:57:13: error: reference to 'rank' is ambiguous 57 | rank[sum[i].y]=i; | ^~~~ In file included from /usr/include/c++/14/bits/stl_pair.h:60, from /usr/include/c++/14/bits/stl_algobase.h:64, from /usr/include/c++/14/algorithm:60, from a.cc:2: /usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank' 1437 | struct rank | ^~~~ a.cc:13:5: note: 'int rank [200010]' 13 | int rank[maxn]; | ^~~~ a.cc:61:29: error: reference to 'rank' is ambiguous 61 | ans+=search(rank[i]-1); | ^~~~ /usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank' 1437 | struct rank | ^~~~ a.cc:13:5: note: 'int rank [200010]' 13 | int rank[maxn]; | ^~~~ a.cc:62:21: error: reference to 'rank' is ambiguous 62 | add(rank[i]); | ^~~~ /usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank' 1437 | struct rank | ^~~~ a.cc:13:5: note: 'int rank [200010]' 13 | int rank[maxn]; | ^~~~
s303019885
p03703
Java
import java.util.*; import java.io.*; import java.math.*; import static java.lang.Math.*; import static java.util.Arrays.*; import static java.util.Collections.*; public class Main{ static long mod=1000000007; static int dx[]={1,-1,0,0}; static int dy[]={0,0,1,-1}; // static int dx[]={1,-1,0,0,1,1,-1,-1}; // static int dy[]={0,0,1,-1,1,-1,1,-1}; // PriorityQueue<Integer> que = new PriorityQueue<Integer>(); //HashMap<Integer,Integer> map = new HashMap<Integer,Integer>(); public static void main(String[] args) throws Exception, IOException{ Reader sc = new Reader(System.in); PrintWriter out=new PrintWriter(System.out); // int n=sc.nextInt(); int n=sc.nextInt(); int k=sc.nextInt(); int d[] = new int[n]; int s[] = new int[n]; long ans = 0; for( int i=0; i<n; i++ ){ d[i] = sc.nextInt() - k; if(i>0) d[i]+=d[i-1]; s[i] = d[i]; } sort(s); s = unique_array(s); bit bit = new bit(s.length + 1); for( int i=0; i<n; i++ ){ if(d[i]>=0)ans++; int t = binarySearch(s, d[i]) + 1; ans += bit.sum(public void testName() throws Exception { }); bit.add(t,1); } out.println(ans); out.flush(); } static int[] unique_array(int d[]) { //d:sorted int id = 1; for( int i=1; i<d.length; i++ ){ if(d[i]!=d[id-1]){ d[id++] = d[i]; } } return copyOf(d, id); } static void db(Object... os){ System.err.println(Arrays.deepToString(os)); } static boolean validpos(int x,int y,int r, int c){ return x<r && 0<=x && y<c && 0<=y; } static boolean bit(long x,int k){ // weather k-th bit (from right) be one or zero return ( 0 < ( (x>>k) & 1 ) ) ? true:false; } } class XY { int x,y,d; XY(int x, int y, int d) { this.x=x; this.y=y; this.d=d; } } class P implements Comparable<P>{ int x,y; P(int x, int y) { this.x=x; this.y=y; } public int compareTo(P p){ return x - p.x; } } class bit { int b[],n; bit(int n){ this.n = n; b = new int[n+1]; } int sum(int i){ int s = 0; while(i > 0){ s += b[i]; i -= i&-i; } return s; } void add(int i, int x){ while(i <= n){ b[i] += x; i += i&-i; } } } class Reader { private BufferedReader x; private StringTokenizer st; public Reader(InputStream in) { x = new BufferedReader(new InputStreamReader(in)); st = null; } public String nextString() throws IOException { while( st==null || !st.hasMoreTokens() ) st = new StringTokenizer(x.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(nextString()); } public long nextLong() throws IOException { return Long.parseLong(nextString()); } public double nextDouble() throws IOException { return Double.parseDouble(nextString()); } }
Main.java:47: error: illegal start of expression ans += bit.sum(public void testName() throws Exception { ^ Main.java:49: error: illegal start of type }); ^ Main.java:50: error: <identifier> expected bit.add(t,1); ^ Main.java:50: error: <identifier> expected bit.add(t,1); ^ Main.java:50: error: illegal start of type bit.add(t,1); ^ Main.java:53: error: class, interface, enum, or record expected out.println(ans); ^ Main.java:54: error: class, interface, enum, or record expected out.flush(); ^ Main.java:55: error: class, interface, enum, or record expected } ^ Main.java:60: error: class, interface, enum, or record expected for( int i=1; i<d.length; i++ ){ ^ Main.java:60: error: class, interface, enum, or record expected for( int i=1; i<d.length; i++ ){ ^ Main.java:60: error: class, interface, enum, or record expected for( int i=1; i<d.length; i++ ){ ^ Main.java:63: error: class, interface, enum, or record expected } ^ Main.java:66: error: class, interface, enum, or record expected } ^ Main.java:72: error: class, interface, enum, or record expected } ^ Main.java:78: error: class, interface, enum, or record expected } ^ Main.java:83: error: class, interface, enum, or record expected } ^ 16 errors
s066813638
p03703
C++
#pragma region include #include <iostream> #include <iomanip> #include <stdio.h> #include <sstream> #include <algorithm> #include <cmath> #include <complex> #include <string> #include <cstring> #include <vector> #include <tuple> #include <bitset> #include <queue> #include <complex> #include <set> #include <map> #include <stack> #include <list> #include <fstream> #include <random> //#include <time.h> #include <ctime> #pragma endregion //#include ///////// #define REP(i, x, n) for(int i = x; i < n; ++i) #define rep(i,n) REP(i,0,n) ///////// #pragma region typedef typedef long long LL; typedef long double LD; typedef unsigned long long ULL; #pragma endregion //typedef ////定数 const int INF = (int)1e9; const LL MOD = (LL)1e9+7; const LL LINF = (LL)1e18; const double PI = acos(-1.0); const double EPS = 1e-9; ///////// using namespace::std; void solve(){ int N; LL K; cin >> N >> K; vector<LL> A(N); //値から欲しい平均値を引く for(int i=0;i<N;++i){ cin >> A[i]; A[i] -= K; } //累積和を取る vector<LL> sum(N); sum[0] = A[0]; for(int i=1;i<N;++i){ sum[i] = sum[i-1] + A[i]; } //累積和に対して座標圧縮する。 vector<LL> B = sum; B.push_back( 0 );//基準を入れておく UNIQUE(B); vector<int> sumC(N);//圧縮されたindex+1に値を変える for(int i=0;i<N;++i){ int index = lower_bound(B.begin(),B.end(),sum[i]) - B.begin(); sumC[i] = index + 1; } int size = B.size(); BITree BIT(size); //基準の値 int index = lower_bound(B.begin(),B.end(),0) - B.begin(); BIT.add(index+1,1);//0の分 LL ans = 0; for(int i=0;i<N;++i){ LL res = BIT.sum( sumC[i] ); ans += res; BIT.add(sumC[i],1); } cout << ans << endl; } #pragma region main signed main(void){ std::cin.tie(0); std::ios::sync_with_stdio(false); std::cout << std::fixed;//小数を10進数表示 cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別 solve(); } #pragma endregion //main()
a.cc: In function 'void solve()': a.cc:68:9: error: 'UNIQUE' was not declared in this scope 68 | UNIQUE(B); | ^~~~~~ a.cc:75:9: error: 'BITree' was not declared in this scope 75 | BITree BIT(size); | ^~~~~~ a.cc:79:9: error: 'BIT' was not declared in this scope 79 | BIT.add(index+1,1);//0の分 | ^~~
s648093349
p03703
C++
#include <cstdio> #include <cstdint> #include <cinttypes> #include <iostream> #include <vector> #include <set> #include <utility> #include <cmath> #include <algorithm> #include <numeric> #include <string> using u8t = std::uint64_t; using i8t = std::int64_t; #define F(I,N) for(i8t I=0,_N=N;I<_N;I++) #define R(V) i8t V;std::cin>>V; #define RV(V,N) std::vector<i8t> V;F(i,N){R(x)V.push_back(x);} #define RL1(line) std::getline(std::cin,line); #define RL(line) std::string line;RL0(line) #define P(X) std::cout<<(X)<<std::endl; int main() { R(N)R(K)RV(a,N); std::vector<i8t> s; i8t sum = 0; F(i,N){ auto d = a[i] - K; sum+=d; s.push_back(sum); } //std::vector<i8t> sorted; std::multiset<i8t> sorted; sorted.insert(0); i8t count=0; F(i,N){ auto s1 = s[i]; auto ins = sorted.upper_bound(s1); //count += std::distance(sorted.begin(), ins); count += ins - sorted.begin(); sorted.insert(ins,s1); } P(count); return 0; }
a.cc: In function 'int main()': a.cc:37:18: error: no match for 'operator-' (operand types are 'std::_Rb_tree_const_iterator<long int>' and 'std::multiset<long int>::iterator' {aka 'std::_Rb_tree<long int, long int, std::_Identity<long int>, std::less<long int>, std::allocator<long int> >::const_iterator'}) 37 | count += ins - sorted.begin(); | ~~~ ^ ~~~~~~~~~~~~~~ | | | | | _Rb_tree_const_iterator<[...]> | _Rb_tree_const_iterator<[...]> In file included from /usr/include/c++/14/string:48, from /usr/include/c++/14/bits/locale_classes.h:40, from /usr/include/c++/14/bits/ios_base.h:41, from /usr/include/c++/14/ios:44, from /usr/include/c++/14/ostream:40, from /usr/include/c++/14/iostream:41, from a.cc:4: /usr/include/c++/14/bits/stl_iterator.h:618:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__y.base() - __x.base())) std::operator-(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)' 618 | operator-(const reverse_iterator<_IteratorL>& __x, | ^~~~~~~~ /usr/include/c++/14/bits/stl_iterator.h:618:5: note: template argument deduction/substitution failed: a.cc:37:33: note: 'std::_Rb_tree_const_iterator<long int>' is not derived from 'const std::reverse_iterator<_Iterator>' 37 | count += ins - sorted.begin(); | ^ /usr/include/c++/14/bits/stl_iterator.h:1790:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__x.base() - __y.base())) std::operator-(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)' 1790 | operator-(const move_iterator<_IteratorL>& __x, | ^~~~~~~~ /usr/include/c++/14/bits/stl_iterator.h:1790:5: note: template argument deduction/substitution failed: a.cc:37:33: note: 'std::_Rb_tree_const_iterator<long int>' is not derived from 'const std::move_iterator<_IteratorL>' 37 | count += ins - sorted.begin(); | ^
s251824642
p03703
C++
#include <bits/stdc++.h> using namespace std; #define int long long struct data { int pos, num; }; main() { int n, k; int sum[200005] = {} bool flag[200005] = {}; int ans = 0; queue < data > que; cin >> n >> k; for(int i = 1; i <= n; i++) { cin >> sum[i]; sum[i] += sum[i - 1]; if(sum[i] >= i * k) { que.push((data) { i, 1 }); flag[i] = true; ans++; } } for(int i = 2; i <= n; i++) { while(true) { data d = que.front(); que.pop(); if(d.pos == i) break; if(!flag[d.pos - 1] && d.pos - 1 > 0 && sum[d.pos - 1] - sum[i - 1] >= (d.pos - i) * k) { que.push((data) { d.pos - 1, i }); flag[d.pos - 1] = true; ans++; } if(!flag[d.pos + 1] &&d.pos + 1 > 0 && sum[d.pos + 1] - sum[i - 1] >= (d.pos - i + 2) * k) { que.push((data) { d.pos + 1, i }); flag[d.pos + 1] = true; ans++; } } } cout << ans << endl; return (0); }
a.cc:10:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 10 | main() | ^~~~ a.cc: In function 'int main()': a.cc:14:3: error: expected ',' or ';' before 'bool' 14 | bool flag[200005] = {}; | ^~~~ a.cc:16:16: error: template argument 1 is invalid 16 | queue < data > que; | ^ a.cc:16:16: error: template argument 2 is invalid a.cc:24:11: error: request for member 'push' in 'que', which is of non-class type 'int' 24 | que.push((data) { i, 1 }); | ^~~~ a.cc:24:17: error: reference to 'data' is ambiguous 24 | que.push((data) { i, 1 }); | ^~~~ In file included from /usr/include/c++/14/string:53, from /usr/include/c++/14/bitset:52, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52, from a.cc:1: /usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)' 344 | data(initializer_list<_Tp> __il) noexcept | ^~~~ /usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])' 334 | data(_Tp (&__array)[_Nm]) noexcept | ^~~~ /usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)' 323 | data(const _Container& __cont) noexcept(noexcept(__cont.data())) | ^~~~ /usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)' 312 | data(_Container& __cont) noexcept(noexcept(__cont.data())) | ^~~~ a.cc:6:8: note: 'struct data' 6 | struct data { | ^~~~ a.cc:25:7: error: 'flag' was not declared in this scope 25 | flag[i] = true; ans++; | ^~~~ a.cc:31:7: error: reference to 'data' is ambiguous 31 | data d = que.front(); que.pop(); | ^~~~ /usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)' 344 | data(initializer_list<_Tp> __il) noexcept | ^~~~ /usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])' 334 | data(_Tp (&__array)[_Nm]) noexcept | ^~~~ /usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)' 323 | data(const _Container& __cont) noexcept(noexcept(__cont.data())) | ^~~~ /usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)' 312 | data(_Container& __cont) noexcept(noexcept(__cont.data())) | ^~~~ a.cc:6:8: note: 'struct data' 6 | struct data { | ^~~~ a.cc:31:33: error: request for member 'pop' in 'que', which is of non-class type 'int' 31 | data d = que.front(); que.pop(); | ^~~ a.cc:32:10: error: 'd' was not declared in this scope 32 | if(d.pos == i) break; | ^ a.cc:34:11: error: 'flag' was not declared in this scope 34 | if(!flag[d.pos - 1] && d.pos - 1 > 0 && sum[d.pos - 1] - sum[i - 1] >= (d.pos - i) * k) { | ^~~~ a.cc:34:16: error: 'd' was not declared in this scope 34 | if(!flag[d.pos - 1] && d.pos - 1 > 0 && sum[d.pos - 1] - sum[i - 1] >= (d.pos - i) * k) { | ^ a.cc:35:13: error: request for member 'push' in 'que', which is of non-class type 'int' 35 | que.push((data) { d.pos - 1, i }); | ^~~~ a.cc:35:19: error: reference to 'data' is ambiguous 35 | que.push((data) { d.pos - 1, i }); | ^~~~ /usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)' 344 | data(initializer_list<_Tp> __il) noexcept | ^~~~ /usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])' 334 | data(_Tp (&__array)[_Nm]) noexcept | ^~~~ /usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)' 323 | data(const _Container& __cont) noexcept(noexcept(__cont.data())) | ^~~~ /usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)' 312 | data(_Container& __cont) noexcept(noexcept(__cont.data())) | ^~~~ a.cc:6:8: note: 'struct data' 6 | struct data { | ^~~~ a.cc:40:11: error: 'flag' was not declared in this scope 40 | if(!flag[d.pos + 1] &&d.pos + 1 > 0 && sum[d.pos + 1] - sum[i - 1] >= (d.pos - i + 2) * k) { | ^~~~ a.cc:40:16: error: 'd' was not declared in this scope 40 | if(!flag[d.pos + 1] &&d.pos + 1 > 0 && sum[d.pos + 1] - sum[i - 1] >= (d.pos - i + 2) * k) { | ^ a.cc:41:13: error: request for member 'push' in 'que', which is of non-class type 'int' 41 | que.push((data) { d.pos + 1, i }); | ^~~~ a.cc:41:19: error: reference to 'data' is ambiguous 41 | que.push((data) { d.pos + 1, i }); | ^~~~ /usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)' 344 | data(initializer_list<_Tp> __il) noexcept | ^~~~ /usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])' 334 | data(_Tp (&__array)[_Nm]) noexcept | ^~~~ /usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)' 323 | data(const _Container& __cont) noexcept(noexcept(__cont.data())) | ^~~~ /usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)' 312 | data(_Container& __cont) noexcept(noexcept(__cont.data())) | ^~~~ a.cc:6:8: note: 'struct data' 6 | struct data { | ^~~~
s847649736
p03703
C++
#include <iostream> #include <vector> using namespace std; int main(void){ int N, K, a; cin >> N >> K; vector<int> vec(N, 0); for(int i = 0; i < N; i ++) { cin >> a; vec[i] = a - K; } long long sum; long long count = 0; for(int i = 0; i < N; i ++) { sum = 0; sum_comp = 0; for(int j = 0; j < N - i; j ++) { sum += vec[i + j]; if(sum >= 0) { count++; } } } cout << count << endl; return 0; }
a.cc: In function 'int main()': a.cc:19:9: error: 'sum_comp' was not declared in this scope 19 | sum_comp = 0; | ^~~~~~~~
s812229274
p03703
C++
#include <iostream> #include <cstdio> #include <vector> #include <cmath> #include <cstring> #include <numeric> #include <algorithm> #include <functional> #include <array> #include <map> #include <queue> #include <limits.h> #include <set> #include <stack> #include <random> #include <complex> #include <unordered_map> #include <nmmintrin.h> #include <chrono> #define rep(i,s,n) for(int i = (s); (n) > i; i++) #define REP(i,n) rep(i,0,n) #define RANGE(x,a,b) ((a) <= (x) && (x) <= (b)) #define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b)) #define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d)) #define PW(x) ((x)*(x)) #define ALL(x) (x).begin(), (x).end() #define MODU 1000000007 #define bitcheck(a,b) ((a >> b) & 1) #define bitset(a,b) ( a |= (1 << b)) #define bitunset(a,b) (a &= ~(1 << b)) #define MP(a,b) make_pair((a),(b)) #define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second)) #define pritnf printf #define scnaf scanf #define itn int #ifdef _MSC_VER #define __builtin_popcount _mm_popcnt_u32 #define __builtin_popcountll _mm_popcnt_u64 #endif using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a%b); } template<typename A, size_t N, typename T> void Fill(A(&array)[N], const T &val) { std::fill((T*)array, (T*)(array + N), val); } #ifdef _MSC_VER #define __builtin_popcount _mm_popcnt_u32 #define __builtin_popcountll _mm_popcnt_u64 #endif class Bitvector { //4byteブロック 全部半径、0-index static const int mask[32]; public: unsigned int* st; unsigned int* blockrank; int sz; Bitvector(int n) { sz = n; st = (unsigned int*)calloc((n + 31) / 32, sizeof(int)); blockrank = (unsigned int*)calloc((n + 31) / 32 + 1, sizeof(int)); if (st == NULL || blockrank == NULL) abort(); } inline void set(int a, bool f) {//後から追加はできない if (f)bitset(st[a / 32], (31 - a % 32)); } inline bool get(int a) { return bitcheck(st[a / 32], (31 - a % 32)); } inline void calcblock() { int cou = 0; REP(i, sz + 1) { if (i && !(i % 32))blockrank[i / 32] = cou; if (i<sz)cou += bitcheck(st[i / 32], (31 - i % 32)); } } int rank(int a, bool t) { int ret = blockrank[a / 32] + (((32 - a % 32) >= 32) ? 0 : _mm_popcnt_u32(st[a / 32] >> (32 - a % 32))); return t ? ret : a - ret; } int select(int a, bool t) { int l = 0, r = sz + 1; while (r - l > 1) { int mid = (l + r) / 2; if (rank(mid, t) >= a) r = mid; else l = mid; } if (rank(r, t) < a) return -1; return r; } void clear() { free(st); free(blockrank); } }; //プリミティブ型だけだよ!!!!(低レベルでうぇぶるので) template<typename T> class WaveletMatrix { public: vector<T> data; vector<Bitvector> bitv; vector<int> border; int bitsize; WaveletMatrix(vector<T>& dat) : bitsize(sizeof(T) * 8), data(dat) { bitv.reserve(bitsize); REP(i, bitsize + 1) bitv.push_back(Bitvector(data.size())); border.resize(bitsize + 1); REP(j, data.size()) bitv[0].set(j, bitcheck(data[j], bitsize - 1)); bitv[0].calcblock(); vector<T> buf[2]; buf[0] = data; buf[1].resize(data.size()); REP(i, bitsize - 1) { border[i + 1] = bitv[i].rank(data.size(), 0); int cou[2] = { 0, border[i + 1] }; REP(j, data.size()) { bitv[i + 1].set(cou[bitv[i].get(j)], bitcheck(buf[i % 2][j], bitsize - i - 2)); buf[1 - i % 2][cou[bitv[i].get(j)]] = buf[i % 2][j] << (i + 1) >> (i + 1); cou[bitv[i].get(j)]++; } bitv[i + 1].calcblock(); } border[bitsize] = bitv[bitsize - 1].rank(data.size(), 0); } pii search(int s, int e, unsigned int t, int b = 0) { if (b == bitsize) return{ s,e }; bool cur = bitcheck(t, bitsize - 1); return search(cur*border[b + 1] + bitv[b].rank(s, cur), cur*border[b + 1] + bitv[b].rank(e, cur), t << 1, b + 1); } int backward(int a, unsigned int t, int b = 0) { if (b == bitsize - 1) return a; backward(bitv[bitsize - b - 1].select(a + 1 - bitcheck(t, 0) * border[bitsize - b], bitcheck(t, 0)) - 1, t >> 1, b + 1); } int rank(int s, int e, T t) { pii r = search(s, e, t); return r.second - r.first; } int select(int a, T t) { pii r = search(0, data.size(), t); return backward(r.first + a - 1, t); } T kthelement(int s, int e, int k, int b = 0) { int eo = bitv[b].rank(e, 0), so = bitv[b].rank(s, 0), cou = eo - so; if (b == bitsize - 1) return cou <= k; return (cou <= k ? kthelement(border[b + 1] + (s - so), border[b + 1] + (s - so) + (e - s - cou), k - cou, b + 1) : kthelement(so, so + cou, k, b + 1)) | ((cou <= k) << (bitsize - b - 1)); } int less(int s, int e, T t, int b = 0) { int eo = bitv[b].rank(e, 0), so = bitv[b].rank(s, 0), cou = (eo - so); if (b == bitsize) return e - s; return bitcheck(t, bitsize - b - 1) ? less(border[b + 1] + (s - so), border[b + 1] + (s - so) + (e - s - cou), t, b + 1) + cou : less(so, so + cou, t, b + 1); } ~WaveletMatrix() { REP(i, bitsize) bitv[i].clear(); } }; signed main() { int n, k; scanf("%d %d", &n, &k); vector<ll> num(n), sarui(n), sa(n); ll ans = 0; ll Min = LLONG_MAX; REP(i, n) { scanf("%lld", &num[i]); sa[i] = num[i] - k; sarui[i] = num[i] - k; if (num[i] >= k) ans++; } for(int i = n-1; 1<= i; i--) { sarui[i-1] += sarui[i]; } for (auto itr : sarui) Min = min(Min, itr); REP(i,n) sarui[i] += -Min+1; WaveletMatrix<ll> wm(sarui); int cur = num[0]; REP(i, n-1) { int cc = wm.less(0, i + 1, -sa[i + 1] + sarui[i+1]-1); ans += i+1 - cc; } printf("%lld\n", ans); return 0; }
In file included from /usr/lib/gcc/x86_64-linux-gnu/14/include/smmintrin.h:812, from /usr/lib/gcc/x86_64-linux-gnu/14/include/nmmintrin.h:31, from a.cc:18: /usr/lib/gcc/x86_64-linux-gnu/14/include/popcntintrin.h: In member function 'int Bitvector::rank(int, bool)': /usr/lib/gcc/x86_64-linux-gnu/14/include/popcntintrin.h:35:1: error: inlining failed in call to 'always_inline' 'int _mm_popcnt_u32(unsigned int)': target specific option mismatch 35 | _mm_popcnt_u32 (unsigned int __X) | ^~~~~~~~~~~~~~ a.cc:85:90: note: called from here 85 | int ret = blockrank[a / 32] + (((32 - a % 32) >= 32) ? 0 : _mm_popcnt_u32(st[a / 32] >> (32 - a % 32))); | ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
s974929712
p03703
C++
#include <iostream> #include <cstdio> #include <vector> #include <cmath> #include <cstring> #include <numeric> #include <algorithm> #include <functional> #include <array> #include <map> #include <queue> #include <limits.h> #include <set> #include <stack> #include <random> #include <complex> #include <unordered_map> #include <nmmintrin.h> #include <chrono> #define rep(i,s,n) for(int i = (s); (n) > i; i++) #define REP(i,n) rep(i,0,n) #define RANGE(x,a,b) ((a) <= (x) && (x) <= (b)) #define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b)) #define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d)) #define PW(x) ((x)*(x)) #define ALL(x) (x).begin(), (x).end() #define MODU 1000000007 #define bitcheck(a,b) ((a >> b) & 1) #define bitset(a,b) ( a |= (1 << b)) #define bitunset(a,b) (a &= ~(1 << b)) #define MP(a,b) make_pair((a),(b)) #define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second)) #define pritnf printf #define scnaf scanf #define itn int #ifdef _MSC_VER #define __builtin_popcount _mm_popcnt_u32 #define __builtin_popcountll _mm_popcnt_u64 #endif using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a%b); } template<typename A, size_t N, typename T> void Fill(A(&array)[N], const T &val) { std::fill((T*)array, (T*)(array + N), val); } #ifdef _MSC_VER #define __builtin_popcount _mm_popcnt_u32 #define __builtin_popcountll _mm_popcnt_u64 #endif class Bitvector { //4byteブロック 全部半径、0-index static const int mask[32]; public: unsigned int* st; unsigned int* blockrank; int sz; Bitvector(int n) { sz = n; st = (unsigned int*)calloc((n + 31) / 32, sizeof(int)); blockrank = (unsigned int*)calloc((n + 31) / 32 + 1, sizeof(int)); if (st == NULL || blockrank == NULL) abort(); } inline void set(int a, bool f) {//後から追加はできない if (f)bitset(st[a / 32], (31 - a % 32)); } inline bool get(int a) { return bitcheck(st[a / 32], (31 - a % 32)); } inline void calcblock() { int cou = 0; REP(i, sz + 1) { if (i && !(i % 32))blockrank[i / 32] = cou; if (i<sz)cou += bitcheck(st[i / 32], (31 - i % 32)); } } int rank(int a, bool t) { int ret = blockrank[a / 32] + (((32 - a % 32) >= 32) ? 0 : _mm_popcnt_u32(st[a / 32] >> (32 - a % 32))); return t ? ret : a - ret; } int select(int a, bool t) { int l = 0, r = sz + 1; while (r - l > 1) { int mid = (l + r) / 2; if (rank(mid, t) >= a) r = mid; else l = mid; } if (rank(r, t) < a) return -1; return r; } void clear() { free(st); free(blockrank); } }; //プリミティブ型だけだよ!!!!(低レベルでうぇぶるので) template<typename T> class WaveletMatrix { public: vector<T> data; vector<Bitvector> bitv; vector<int> border; int bitsize; WaveletMatrix(vector<T>& dat) : bitsize(sizeof(T) * 8), data(dat) { bitv.reserve(bitsize); REP(i, bitsize + 1) bitv.push_back(Bitvector(data.size())); border.resize(bitsize + 1); REP(j, data.size()) bitv[0].set(j, bitcheck(data[j], bitsize - 1)); bitv[0].calcblock(); vector<T> buf[2]; buf[0] = data; buf[1].resize(data.size()); REP(i, bitsize - 1) { border[i + 1] = bitv[i].rank(data.size(), 0); int cou[2] = { 0, border[i + 1] }; REP(j, data.size()) { bitv[i + 1].set(cou[bitv[i].get(j)], bitcheck(buf[i % 2][j], bitsize - i - 2)); buf[1 - i % 2][cou[bitv[i].get(j)]] = buf[i % 2][j] << (i + 1) >> (i + 1); cou[bitv[i].get(j)]++; } bitv[i + 1].calcblock(); } border[bitsize] = bitv[bitsize - 1].rank(data.size(), 0); } pii search(int s, int e, unsigned int t, int b = 0) { if (b == bitsize) return{ s,e }; bool cur = bitcheck(t, bitsize - 1); return search(cur*border[b + 1] + bitv[b].rank(s, cur), cur*border[b + 1] + bitv[b].rank(e, cur), t << 1, b + 1); } int backward(int a, unsigned int t, int b = 0) { if (b == bitsize - 1) return a; backward(bitv[bitsize - b - 1].select(a + 1 - bitcheck(t, 0) * border[bitsize - b], bitcheck(t, 0)) - 1, t >> 1, b + 1); } int rank(int s, int e, T t) { pii r = search(s, e, t); return r.second - r.first; } int select(int a, T t) { pii r = search(0, data.size(), t); return backward(r.first + a - 1, t); } T kthelement(int s, int e, int k, int b = 0) { int eo = bitv[b].rank(e, 0), so = bitv[b].rank(s, 0), cou = eo - so; if (b == bitsize - 1) return cou <= k; return (cou <= k ? kthelement(border[b + 1] + (s - so), border[b + 1] + (s - so) + (e - s - cou), k - cou, b + 1) : kthelement(so, so + cou, k, b + 1)) | ((cou <= k) << (bitsize - b - 1)); } int less(int s, int e, T t, int b = 0) { int eo = bitv[b].rank(e, 0), so = bitv[b].rank(s, 0), cou = (eo - so); if (b == bitsize) return e - s; return bitcheck(t, bitsize - b - 1) ? less(border[b + 1] + (s - so), border[b + 1] + (s - so) + (e - s - cou), t, b + 1) + cou : less(so, so + cou, t, b + 1); } ~WaveletMatrix() { REP(i, bitsize) bitv[i].clear(); } }; signed main() { int n, k; scanf("%d %d", &n, &k); vector<ll> num(n), sarui(n), sa(n); ll ans = 0; ll Min = LLONG_MAX; REP(i, n) { scanf("%d", &num[i]); sa[i] = num[i] - k; sarui[i] = num[i] - k; if (num[i] >= k) ans++; } for(int i = n-1; 1<= i; i--) { sarui[i-1] += sarui[i]; } for (auto itr : sarui) Min = min(Min, itr); REP(i,n) sarui[i] += -Min+1; WaveletMatrix<ll> wm(sarui); int cur = num[0]; REP(i, n-1) { int cc = wm.less(0, i + 1, -sa[i + 1] + sarui[i+1]-1); ans += i+1 - cc; } printf("%lld\n", ans); return 0; }
In file included from /usr/lib/gcc/x86_64-linux-gnu/14/include/smmintrin.h:812, from /usr/lib/gcc/x86_64-linux-gnu/14/include/nmmintrin.h:31, from a.cc:18: /usr/lib/gcc/x86_64-linux-gnu/14/include/popcntintrin.h: In member function 'int Bitvector::rank(int, bool)': /usr/lib/gcc/x86_64-linux-gnu/14/include/popcntintrin.h:35:1: error: inlining failed in call to 'always_inline' 'int _mm_popcnt_u32(unsigned int)': target specific option mismatch 35 | _mm_popcnt_u32 (unsigned int __X) | ^~~~~~~~~~~~~~ a.cc:85:90: note: called from here 85 | int ret = blockrank[a / 32] + (((32 - a % 32) >= 32) ? 0 : _mm_popcnt_u32(st[a / 32] >> (32 - a % 32))); | ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
s062255906
p03703
C++
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; const long long N=4e5+1e3+7; long long n,a[N],k,s[N],ans; long long tot,root,size[N],num[N],key[N],fa[N],son[N][2]; void pushup(long long x) { size[x]=size[son[x][0]]+size[son[x][1]]+num[x]; } void rotate(long long x) { long long y=fa[x],z=fa[y],t=(son[y][0]==x); if(z) son[z][son[z][1]==y]=x; fa[x]=z; son[y][!t]=son[x][t]; fa[son[y][!t]]=y; son[x][t]=y; fa[y]=x; pushup(y); pushup(x); } void splay(long long x,long long s) { while(fa[x]!=s) { long long y=fa[x],z=fa[y]; if(z!=s) if(son[z][0]==y^son[y][0]==x) rotate(x); else rotate(y); rotate(x); } if(s==0) root=x; } void insert(long long &x,long long v,long long s) { if(!x) { x=++tot; size[x]=num[x]=1; son[x][0]=son[x][1]=0; key[x]=v; fa[x]=s; splay(x,0); return; } if(v==key[x]) { num[x]++; size[x]++; splay(x,0); return; } insert(son[x][v>key[x]],v,x); pushup(x); } long long get(long long v) { long long x=root; while(x&&v!=key[x]) x=son[x][v>key[x]]; return x; } void del(long long x) { x=get(x); if(!x) return; splay(x,0); if(num[x]>1) { num[x]--; size[x]--; return; } if(!son[x][0]||!son[x][1]) root=son[x][0]+son[x][1]; else { long long y=son[x][1]; while(son[y][0]) y=son[y][0]; splay(y,x); son[y][0]=son[x][0]; fa[son[y][0]]=y; root=y; } fa[root]=0; pushup(root); } long long rank(long long v) { insert(root,v,0); long long ans=size[son[root][0]]; del(v); return ans; } int main() { cin>>n>>k; for(long long i=1;i<=n;i++) cin>>a[i],a[i]-=k,s[i]=s[i-1]+a[i]; insert(root,0,0); for(long long i=1;i<=n;i++) { insert(root,s[i],0); ans+=rank(s[i]+1)-1; } cout<<ans; }
a.cc: In function 'void pushup(long long int)': a.cc:15:9: error: reference to 'size' is ambiguous 15 | size[x]=size[son[x][0]]+size[son[x][1]]+num[x]; | ^~~~ In file included from /usr/include/c++/14/string:53, from /usr/include/c++/14/bits/locale_classes.h:40, from /usr/include/c++/14/bits/ios_base.h:41, from /usr/include/c++/14/ios:44, from /usr/include/c++/14/ostream:40, from /usr/include/c++/14/iostream:41, from a.cc:3: /usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])' 272 | size(const _Tp (&)[_Nm]) noexcept | ^~~~ /usr/include/c++/14/bits/range_access.h:262:5: note: 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)' 262 | size(const _Container& __cont) noexcept(noexcept(__cont.size())) | ^~~~ a.cc:11:20: note: 'long long int size [401007]' 11 | long long tot,root,size[N],num[N],key[N],fa[N],son[N][2]; | ^~~~ a.cc:15:17: error: reference to 'size' is ambiguous 15 | size[x]=size[son[x][0]]+size[son[x][1]]+num[x]; | ^~~~ /usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])' 272 | size(const _Tp (&)[_Nm]) noexcept | ^~~~ /usr/include/c++/14/bits/range_access.h:262:5: note: 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)' 262 | size(const _Container& __cont) noexcept(noexcept(__cont.size())) | ^~~~ a.cc:11:20: note: 'long long int size [401007]' 11 | long long tot,root,size[N],num[N],key[N],fa[N],son[N][2]; | ^~~~ a.cc:15:33: error: reference to 'size' is ambiguous 15 | size[x]=size[son[x][0]]+size[son[x][1]]+num[x]; | ^~~~ /usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])' 272 | size(const _Tp (&)[_Nm]) noexcept | ^~~~ /usr/include/c++/14/bits/range_access.h:262:5: note: 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)' 262 | size(const _Container& __cont) noexcept(noexcept(__cont.size())) | ^~~~ a.cc:11:20: note: 'long long int size [401007]' 11 | long long tot,root,size[N],num[N],key[N],fa[N],son[N][2]; | ^~~~ a.cc: In function 'void insert(long long int&, long long int, long long int)': a.cc:57:17: error: reference to 'size' is ambiguous 57 | size[x]=num[x]=1; | ^~~~ /usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])' 272 | size(const _Tp (&)[_Nm]) noexcept | ^~~~ /usr/include/c++/14/bits/range_access.h:262:5: note: 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)' 262 | size(const _Container& __cont) noexcept(noexcept(__cont.size())) | ^~~~ a.cc:11:20: note: 'long long int size [401007]' 11 | long long tot,root,size[N],num[N],key[N],fa[N],son[N][2]; | ^~~~ a.cc:67:17: error: reference to 'size' is ambiguous 67 | size[x]++; | ^~~~ /usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])' 272 | size(const _Tp (&)[_Nm]) noexcept | ^~~~ /usr/include/c++/14/bits/range_access.h:262:5: note: 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)' 262 | size(const _Container& __cont) noexcept(noexcept(__cont.size())) | ^~~~ a.cc:11:20: note: 'long long int size [401007]' 11 | long long tot,root,size[N],num[N],key[N],fa[N],son[N][2]; | ^~~~ a.cc: In function 'void del(long long int)': a.cc:94:17: error: reference to 'size' is ambiguous 94 | size[x]--; | ^~~~ /usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])' 272 | size(const _Tp (&)[_Nm]) noexcept | ^~~~ /usr/include/c++/14/bits/range_access.h:262:5: note: 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)' 262 | size(const _Container& __cont) noexcept(noexcept(__cont.size())) | ^~~~ a.cc:11:20: note: 'long long int size [401007]' 11 | long long tot,root,size[N],num[N],key[N],fa[N],son[N][2]; | ^~~~ a.cc: In function 'long long int rank(long long int)': a.cc:116:23: error: reference to 'size' is ambiguous 116 | long long ans=size[son[root][0]]; | ^~~~ /usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])' 272 | size(const _Tp (&)[_Nm]) noexcept | ^~~~ /usr/include/c++/14/bits/range_access.h:262:5: note: 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)' 262 | size(const _Container& __cont) noexcept(noexcept(__cont.size())) | ^~~~ a.cc:11:20: note: 'long long int size [401007]' 11 | long long tot,root,size[N],num[N],key[N],fa[N],son[N][2]; | ^~~~ a.cc: In function 'int main()': a.cc:130:22: error: reference to 'rank' is ambiguous 130 | ans+=rank(s[i]+1)-1; | ^~~~ In file included from /usr/include/c++/14/bits/move.h:37, from /usr/include/c++/14/bits/exception_ptr.h:41, from /usr/include/c++/14/exception:166, from /usr/include/c++/14/ios:41: /usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank' 1437 | struct rank | ^~~~ a.cc:113:11: note: 'long long int rank(long long int)' 113 | long long rank(long long v) | ^~~~
s139793370
p03703
C++
#include<algorithm> #include<cmath> #include<iomanip> #include<iostream> #include<map> #include<numeric> #include<queue> #include<set> #include<sstream> #include<unordered_map> #include<unordered_set> #include<vector> using namespace std; using uint = unsigned int; using ll = long long; const int M = 1e9 + 7; const ll MLL = 1e18L + 9; #pragma unused(M) #pragma unused(MLL) #ifdef LOCAL #include"rprint.hpp" #else template <ostream& out = cout, class... T> void prints(T&&...){ } template <ostream& out = cout, class... T> void printd(T&&...){ } template <ostream& out = cout, class... T> void printb(T&&...){ } template <ostream& out = cout, class... T> void printArr(T&&...){ } #endif struct Node{ Node *l = nullptr, *r = nullptr; int value, cnt = 1; Node(int value): value(value) { } }; struct Sorted { Node* root = nullptr; ll added = 0; void insert(int num){ added -= num; num += added; Node* n = root; if(!root){ root = new Node(num); return; } while(n){ // prints(n); if(n->value <= num){ n->cnt++; if(!n->r){ n->r = new Node(num); break; } n = n->r; }else{ // n->cnt++; if(!n->l){ n->l = new Node(num); break; } n = n->l; } } // n = new Node(num); } int beq(int num){ num += added; Node* n = root; int acc = 0; while(n){ if(n->value > num){ acc += n->cnt; n = n->l; }else if(n->value == num){ return n->cnt + acc; }else{ n = n->r; } } return acc; } // int add(int num){ // added += num; // } }; int main(){ int n, k; cin >> n >> k; Sorted sorted; vector<int> as(n); ll ans = 0; for(int i = 0; i < n; i++){ cin >> as[i]; } reverse(as.begin(), as.end()); for(int i = 0; i < n; i++){ int a = as[i]; a -= k; // ans += sorted.beq(- a); // sorted.add(a); sorted.insert(a); ans += sorted.beq(0); printd(ans); printd(sorted.added); printBTree(sorted.root); } cout << ans << '\n'; return 0; }
a.cc: In function 'int main()': a.cc:96:9: error: 'printBTree' was not declared in this scope; did you mean 'printArr'? 96 | printBTree(sorted.root); | ^~~~~~~~~~ | printArr
s749519368
p03703
C++
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int N = 0, K = 0; int ans = 0; cin >> N >> K; vector<double> v(N); for (int i = 0; i < N;i++){ cin >> v[i]; } for (int i = 0; i < N;i++){ double sum = 0; double c = 0; for (int j = i; j < N;j++){ sum += v[i]; c++; if(sum/c=>K) ans++; } } return 0; }
a.cc: In function 'int main()': a.cc:21:22: error: expected primary-expression before '>' token 21 | if(sum/c=>K) | ^