Submission #679832

#TimeUsernameProblemLanguageResultExecution timeMemory
679832myrcellaFinancial Report (JOI21_financial)C++17
Compilation error
0 ms0 KiB
//by szh #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pii pair<int,int> #define pll pair<long long,long long> #define pb push_back #define debug(x) cerr<<#x<<"="<<x<<endl #define pq priority_queue #define inf 0x3f #define rep(i,a,b) for (int i=a;i<(b);i++) #define MP make_pair #define SZ(x) (int(x.size())) #define ll long long #define mod 1000000007 #define ALL(x) x.begin(),x.end() void inc(int &a,int b) {a=(a+b)%mod;} void dec(int &a,int b) {a=(a-b+mod)%mod;} int lowbit(int x) {return x&(-x);} ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;} const int maxn = 3e5+10; int fa[maxn]; int getf(int x) { if (fa[x]==x) return x; else return fa[x] = getf(fa[x]); } int n,m; bool chosen[maxn]; int a[maxn]; int rend[maxn]; set <int> pos; vector <pii> b; int sz[maxn]; int tree[maxn*4],f[maxn]; void merge(int x,int y) { int fx = getf(x),fy = getf(y); fa[fy] = fx; if (sz[fx]+sz[fy]>=m) { rep(i,fx,fx+sz[x]-m) pos.insert(i); } sz[fx] += sz[fy]; } void add(int tmp) { chosen[tmp]=1; if (m==1) pos.insert(tmp); if (tmp!=0 and chosen[tmp-1]) merge(tmp-1,tmp); if (tmp+1<n and chosen[tmp+1]) merge(tmp,tmp+1); } void update(int c,int cl,int cr,int pos) { if (cl==cr) tree[c] = f[pos]; else { int mid=cl+cr>>1; if (pos<=mid) update(c<<1,cl,mid,pos); else update(c<<1|1,mid+1,cr,pos); tree[c] = max(tree[c<<1],tree[c<<1|1]); } } int query(int c,int cl,int cr,int l ,int r) { if (l<=cl and cr<=r) return tree[c]; int mid=cl+cr>>1; int ret = 0; if (l<=mid) ret = query(c<<1,cl,mid,l,r); if (r>mid) ret = max(ret,query(c<<1|1,mid+1,cr,l,r)); return ret; } int main() { // freopen("input.txt","r",stdin); std::ios::sync_with_stdio(false);cin.tie(0); cin>>n>>m; rep(i,0,n) cin>>a[i],b.pb({a[i],i}),fa[i]=i,sz[i] = i; sort(ALL(b)); reverse(ALL(b)); int cur = 0; rep(i,0,n) { while (cur<n and b[cur].fi>b[i].fi) add(b[cur++].se); auto it = upper_bound(ALL(pos),b[i].se); int tmp; if (it==pos.end()) tmp = n-m; else tmp = *it; rend[b[i].se] = tmp+m-1; } //rep(i,0,n) debug(rend[i]); cur = 0; int ans = 0; rep(i,0,n) { while (cur<n and b[cur].fi>b[i].fi) update(1,0,n-1,b[cur++].se); int val = 1; val += query(1,0,n-1,b[i].se,rend[b[i].se]); f[b[i].se] = val; //cout<<b[i].se<<" "<<rend[b[i].se]<<" "<<val<<endl; ans = max(ans,val); } cout<<ans; return 0; }

Compilation message (stderr)

Main.cpp: In function 'void update(int, int, int, int)':
Main.cpp:62:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   62 |   int mid=cl+cr>>1;
      |           ~~^~~
Main.cpp: In function 'int query(int, int, int, int, int)':
Main.cpp:71:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   71 |  int mid=cl+cr>>1;
      |          ~~^~~
Main.cpp: In function 'int main()':
Main.cpp:92:3: error: reference to 'rend' is ambiguous
   92 |   rend[b[i].se] = tmp+m-1;
      |   ^~~~
In file included from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from Main.cpp:2:
/usr/include/c++/10/bits/range_access.h:211:5: note: candidates are: 'template<class _Tp> constexpr std::reverse_iterator<const _Tp*> std::rend(std::initializer_list<_Tp>)'
  211 |     rend(initializer_list<_Tp> __il)
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:191:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr std::reverse_iterator<_Tp*> std::rend(_Tp (&)[_Nm])'
  191 |     rend(_Tp (&__arr)[_Nm])
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:171:5: note:                 'template<class _Container> constexpr decltype (__cont.rend()) std::rend(const _Container&)'
  171 |     rend(const _Container& __cont) -> decltype(__cont.rend())
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:161:5: note:                 'template<class _Container> constexpr decltype (__cont.rend()) std::rend(_Container&)'
  161 |     rend(_Container& __cont) -> decltype(__cont.rend())
      |     ^~~~
Main.cpp:36:5: note:                 'int rend [300010]'
   36 | int rend[maxn];
      |     ^~~~
Main.cpp:100:32: error: reference to 'rend' is ambiguous
  100 |   val += query(1,0,n-1,b[i].se,rend[b[i].se]);
      |                                ^~~~
In file included from /usr/include/c++/10/string:54,
                 from /usr/include/c++/10/bits/locale_classes.h:40,
                 from /usr/include/c++/10/bits/ios_base.h:41,
                 from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from Main.cpp:2:
/usr/include/c++/10/bits/range_access.h:211:5: note: candidates are: 'template<class _Tp> constexpr std::reverse_iterator<const _Tp*> std::rend(std::initializer_list<_Tp>)'
  211 |     rend(initializer_list<_Tp> __il)
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:191:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr std::reverse_iterator<_Tp*> std::rend(_Tp (&)[_Nm])'
  191 |     rend(_Tp (&__arr)[_Nm])
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:171:5: note:                 'template<class _Container> constexpr decltype (__cont.rend()) std::rend(const _Container&)'
  171 |     rend(const _Container& __cont) -> decltype(__cont.rend())
      |     ^~~~
/usr/include/c++/10/bits/range_access.h:161:5: note:                 'template<class _Container> constexpr decltype (__cont.rend()) std::rend(_Container&)'
  161 |     rend(_Container& __cont) -> decltype(__cont.rend())
      |     ^~~~
Main.cpp:36:5: note:                 'int rend [300010]'
   36 | int rend[maxn];
      |     ^~~~