Codeforces Round #799 (Div. 4)
Posted skywalker767
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #799 (Div. 4)相关的知识,希望对你有一定的参考价值。
第一次ak cf, 虽然是div4.
看了题解,用的线段树…QAQ,我感觉完全可以不用那么麻烦。
我的思路:每一个数如果想要和前面的连成一个区间,只需要看上一个这个数出现的位置。如果把两边连起来的贡献是大于1,那么就连起来,否则,就不和前面连起来,同时更新区间最大值,记录r,在结束后,倒着找l。
时间复杂度的话,很容易证明,扫一遍O(n)
, 倒着找O(n)
,大概就是线性的复杂度。
H - Gambling
#include <bits/stdc++.h>
using namespace std;
#define endl '\\n'
#define pb push_back
#define mk make_pair
#define PI acos(-1)
#define lowbit(x) (x & (-x))
#define sz(x) ((int)(x).size())
#define all(a) a.begin() , a.end()
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define pre(i, b, a) for (int i = (b); i >= (a); --i)
#define debug(x) cout << #x << ": " << x << endl
typedef long long LL;
typedef long double db;
typedef pair<int , int > PII;
const int INF = 0x3f3f3f3f;
const LL MOD = 1000000007;
LL gcd(LL a, LL b) return b?gcd(b,a%b):a;
LL qmi(LL a , LL b , LL p)a %= p;LL res = 1 % p;while(b) if (b & 1)res = res * a % p;a = a * a % p;b >>= 1;return res;
LL qmul(LL x, LL y, LL m) x %= m, y %= m;LL d = ((long double)x * y / m);d = x * y - d * m;if (d >= m) d -= m;if (d < 0) d += m;return d;
template<class T>void read(T &x)T s=0,w=1;char ch=getchar();while(ch<'0'||ch>'9')
if(ch=='-')w=-1;ch=getchar();while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();x = s*w;
template<class H, class... T> void read(H& h, T&... t) read(h);read(t...);
int _;
//head
void solve()
int n;scanf("%d" , &n);
std::vector<int> v(n + 1) , w(n + 1 , 0);
for (int i = 1; i <= n;i ++) scanf("%d" , &v[i]);
std::map<int, int> mp;
int maxx = 0;
int l , r;
for (int i = 1;i <= n;i ++)
w[i] = 1;
if (mp[v[i]])
w[i] = max(1 , 1 - (i - mp[v[i]] - 1) + w[mp[v[i]]]);
mp[v[i]] = i;
// maxx = max(maxx , w[i]);
if (maxx < w[i])
r = i;
maxx = w[i];
int temp = v[r];
int cnt = 0;
// printf("%d #\\n" , r);
for (int i = r;i >= 1;i --)
if (v[i] == temp) cnt ++;
else cnt --;
// cout << "# " << cnt << endl;
if (cnt == maxx)
printf("%d %d %d\\n" , temp , i , r);
break;
// for (int i = 1;i <= n;i ++) printf("%d " , w[i]);
// printf("\\n");
// printf("%d %d\\n" ,maxx , 1 << maxx);
int main()
read(_); while (_ --) solve();
return 0;
以上是关于Codeforces Round #799 (Div. 4)的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Round #799 (Div. 4)
Codeforces Round #799 (Div. 4)
Codeforces Round #799(Div. 4,CF1692)全题解
Codeforces Round #413, rated, Div. 1 + Div. 2 C. Fountains(贪心 or 树状数组)
Codeforces Round #436 E. Fire(背包dp+输出路径)
Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) C. Fountains 树状数组维护区间最大值(示(代