首页 > 其他分享 >MSU Trinity Contest Petrozavodsk Winter Camp 2014

MSU Trinity Contest Petrozavodsk Winter Camp 2014

时间:2022-10-08 11:22:44浏览次数:59  
标签:Winter val Contest int MSU seg void id dp

题目列表

A.ABBA

题意:
Solution 思路:
Code

const int N = 1000010;
int n, q, a[N], ans[N];
vector<pair<int,int>> qu[N];
struct node {
	int val;
} seg[N * 4];
void update(int id) {
	seg[id].val = min(seg[id * 2].val, seg[id * 2 + 1].val);
}
void change(int id, int l, int r, int pos, int val) {
	if (l == r) {
		seg[id].val = val;
	} else {
		int mid = (l + r) / 2;
		if (pos <= mid) change(id * 2, l, mid, pos, val);
		else change(id * 2 + 1, mid + 1, r, pos, val);
		update(id);
	}
}
int search(int id, int l, int r, int d) {
	if (l == r) return l;
	int mid = (l + r) / 2;
	if (seg[id * 2].val < d) return search(id * 2, l, mid, d);
	else return search(id * 2 + 1, mid + 1, r, d);
} 
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		a[i] = min(a[i], n + 1);
	}
	scanf("%d", &q);
	for (int i = 1; i <= q;i++) {
		int l, r;
		scanf("%d%d", &l, &r);
		qu[r].push_back({l, i});
	}
	for (int r = 1; r <= n; r++) {
		change(1, 0, n + 1, a[r], r);
		for (auto que : qu[r]) {
			ans[que.second] = search(1, 0, n + 1, que.first);
		}
	}
	for (int i = 1; i <= q; i++) {
		printf("%d\n", ans[i]);
	}
}

D. Short Enough Task

Solution 思路:
Code
void solve() {
    ll n, k;
    cin >> n >> k;
    long double ans = n;
    if (k == 1) {
        cout << fixed << setprecision(10) << (long double)(1 + n)*(long double)n/ 2.0 << endl;
    } else {
        long double   tmp = 1;
        for (int i = 1; i <= n && i <= 1e6; ++i) {
            if((i&1)){
                tmp*=k;
            }
            ans += ( ((n - i) * 1.0) / tmp); 
        }
        cout << fixed << setprecision(10) << ans << endl;
    }
}

F.Just Another Sequence Problem

Solution 思路:
Code
const int N = 2010;
/* dp[i][j]代表最后一块是i->j*/
dp[i][j] = dp[k][i] 
ll dp[N][N];
void solve() {
    int n;
    cin >> n;
    vector a(n + 1), pre(n + 1);
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        pre[i] = pre[i - 1] + a[i];
    }
    for (int i = 2; i <= n; ++i) {
        for (int j = i; j <= n; ++j) {
            dp[i][j]=INT_MIN;
            for (int k = 1; k <= i - 1; ++k) {
                dp[i][j] = max(dp[i][j], dp[k][i - 1] + (pre[i - 1] - pre[k - 1]) * (pre[j] - pre[i - 1]));
            }
        }
    }
    ll ans =0;
    for (int i = 1; i <= n; ++i) {
        ans = max(ans, dp[i][n]);
    }
    cout << ans << '\n';
}

标签:Winter,val,Contest,int,MSU,seg,void,id,dp
From: https://www.cnblogs.com/tentenn/p/16753910.html

相关文章

  • The 2021 ICPC Asia Shenyang Regional Contest
    比赛链接:https://codeforces.com/gym/103427B.BitwiseExclusive-ORSequence题意:给定\(m\)个限制,要求构造一个全是非负整数的序列\(a\),每个限制告诉\(u,v,w\),......
  • 「题解」Codeforces GYM 102268 J Jealous Split(300iq Contest 1 J)
    怎么想到的结论?结论是,如果把看成最小化\(\sum{s_i}^2\),那么一定满足条件。证明是考虑如果相邻两段\(s>t\),如果不满足条件即\(s-t>\max\),说明将\(s\)和\(t\)交界处......
  • AtCoder Beginner Contest 271
    咕咕咕咕。E-SubsequencePath最短路问题变种,Dijkstra最短路改改就行了。AC代码//Problem:E-SubsequencePath//Contest:AtCoder-KYOCERAProgrammingC......
  • AtCoder Regular Contest 149
    ARC149A-RepdigitNumber符合条件的数一共只有\(9N\)个,随便怎么做都行。ACCodeARC149B-TwoLISSum这个操作相当于我们可以将\(A\)任意排列,然后对\(B\)进行......
  • AtCoder Regular Contest 149(持续更新)
    Preface最近国庆在外面玩的有点high啊,欠了一篇AT和两篇CF没写,今天先浅浅写一下这场当时10.2号在外面玩得有点晚了,到寝室刚好比赛开始,晚饭都没吃就开干了主要是C写的太久......
  • AtCoder Regular Contest 149
    A发现所有数字都相同的数一共只有\(10^6\)种,考虑枚举每种情况,关键在于如何判断一个数\(\bmodm\)是否为\(0\)。考虑\(9\bmod8=1\),而\(99\bmod8=(9\times10+9)\b......
  • AtCoder Beginner Contest 271
    AtCoderBeginnerContest271D-FlipandAdjust一共有\(N\)张牌,每一面都写着一个整数。卡\(i(1\lei\leN)\)前面写着整数\(a_i\),后面写着整数\(b_i\)。你可......
  • AtCoder Regular Contest 137 D
    一道很好的题目,运用了很多不同的技巧。结论1:枚举变换次数\(k\),若\(A_{i}\)对答案有贡献,当且仅当\(C_{n-i+k-1}^{k-1}\equiv1\mod2\)。首先我们可以统计\(A_{p}\)对......
  • CSP模拟练习赛1 https://www.luogu.com.cn/contest/82861#problems
    P1321单词覆盖还原简单思路字符串#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<queue>#include<map>#definelllonglon......
  • 2018-2019 ACM-ICPC, Asia Seoul Regional Contest(CF GYM 101987) Problem K. TV Sho
    ProblemSolution设\(p_{i,R/B}\)为第\(i\)号节点染成R或B所代表的点。考虑2-SAT,对于每一个猜的操作,其中任意一个与猜的答案颜色不同,则其他两个必须相同。我们暴力进行......