제출 #1126470

#제출 시각아이디문제언어결과실행 시간메모리
1126470thelegendary08서열 (APIO23_sequence)C++17
28 / 100
2096 ms6284 KiB
#include "sequence.h" #include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> #define pb push_back #define ll long long int #define vi vector<int> #define vvi vector<vector<int>> #define vll vector<long long int> #define vvll vector<vector<long long int>> #define pii pair<int, int> #define vpii vector<pair<int, int>> #define vpll vector<pair<long long int, long long int>> #define pqpll priority_queue<pair<long long int, long long int>> #define vc vector<char> #define vvc vector<vector<char>> #define vb vector<bool> #define mii map<int,int> #define mll map<long long int, long long int> #define mivi map<int,vector<int>> #define f0r(i,n) for(int i=0;i<n;i++) #define FOR(i,k,n) for(int i=k;i<n;i++) using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>os; int sequence(int n, std::vector<int> v) { int ans = 0; for(int sz = 1; sz <= n; sz++){ os s; vi cnt(n+1); for(int i = 0; i<sz; i++){ s.insert(v[i]); cnt[v[i]]++; } f0r(j, s.size()){ //cout<<*s.find_by_order(j)<<' '; } //cout<<'\n'; if(sz % 2 == 1){ int med = *s.find_by_order(sz / 2); if(cnt[med] == 3){ //cout<<med<<' '<<sz<<' '<<i<<'\n'; } ans = max(ans, cnt[med]); } else{ int m1 = *s.find_by_order(sz/2-1); int m2 = *s.find_by_order(sz/2); if(cnt[m1] == 3){ //cout<<m1<<' '<<sz<<' '<<i<<'\n'; f0r(j, s.size()){ //cout<<*s.find_by_order(j)<<' '; } //cout<<'\n'; } if(cnt[m2] == 3){ //cout<<m2<<' '<<sz<<' '<<i<<'\n'; } ans = max(ans, cnt[m1]); ans = max(ans, cnt[m2]); } for(int i = sz; i<n; i++){ s.erase(s.find_by_order(s.order_of_key(v[i-sz]))); s.insert(v[i]); f0r(j, s.size()){ //cout<<*s.find_by_order(j)<<' '; } //cout<<'\n'; cnt[v[i]]++; cnt[v[i-sz]]--; if(sz % 2 == 1){ int med = *s.find_by_order(sz / 2); if(cnt[med] == 3){ //cout<<med<<' '<<sz<<' '<<i<<'\n'; } ans = max(ans, cnt[med]); } else{ int m1 = *s.find_by_order(sz/2-1); int m2 = *s.find_by_order(sz/2); if(cnt[m1] == 3){ //cout<<m1<<' '<<sz<<' '<<i<<'\n'; f0r(j, s.size()){ //cout<<*s.find_by_order(j)<<' '; } //cout<<'\n'; } if(cnt[m2] == 3){ //cout<<m2<<' '<<sz<<' '<<i<<'\n'; } ans = max(ans, cnt[m1]); ans = max(ans, cnt[m2]); } } //cout<<'\n'; } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...