Codeforces Round #645 (Div. 2)

A

include <bits/stdc++.h>

define all(n) (n).begin(), (n).end()

define se second

define fi first

define pb push_back

define mp make_pair

define sqr(n) (n)*(n)

define rep(i,a,b) for(int i=a;i<=b;++i)

define per(i,a,b) for(int i=a;i>=b;--i)

using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector VI;
typedef double db;

const int N = 1e5 + 5;

int n, m, _, k;

int main()
{
ios::sync_with_stdio(0); cin.tie(0);
for (cin >> _; ; --)
{
int a, b; cin >> a >> b;
if (a % 2 == 0 || b % 2 == 0) cout << a * b / 2 << '\n';
else cout << a * b / 2 + 1 << '\n';
}
return 0;
}

B

先排序, 全叫过来,再倒着判断是否能叫过来

include <bits/stdc++.h>

define all(n) (n).begin(), (n).end()

define se second

define fi first

define pb push_back

define mp make_pair

define sqr(n) (n)*(n)

define rep(i,a,b) for(int i=a;i<=b;++i)

define per(i,a,b) for(int i=a;i>=b;--i)

using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector VI;
typedef double db;

const int N = 1e5 + 5;

int n, m, _, k;
int a[N];

int main()
{
ios::sync_with_stdio(0); cin.tie(0);
for (cin >> _; ; --)
{
cin >> n;
rep (i, 1, n) cin >> a[i];
sort(a + 1, a + 1 + n);

    int ans = 1 + n;
    for (int c = n; c && a[c] > ans - 1; --c, --ans);
    cout << ans << '\n';
}
return 0;

}

C

斜着看, 没向下走一步, +1

include <bits/stdc++.h>

define all(n) (n).begin(), (n).end()

define se second

define fi first

define pb push_back

define mp make_pair

define sqr(n) (n)*(n)

define rep(i,a,b) for(int i=a;i<=b;++i)

define per(i,a,b) for(int i=a;i>=b;--i)

using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector VI;
typedef double db;

const int N = 1e5 + 5;

int n, m, _, k;

int main()
{
ios::sync_with_stdio(0); cin.tie(0);
for (cin >> _; ; --)
{
ll x, y, a, b;
cin >> x >> y >> a >> b;
ll ans = (a - x) * (b - y) + 1;
cout << ans << '\n';
}
return 0;
}

D

尺取法

include <bits/stdc++.h>

define all(n) (n).begin(), (n).end()

define se second

define fi first

define pb push_back

define mp make_pair

define sqr(n) (n)*(n)

define rep(i,a,b) for(int i=a;i<=b;++i)

define per(i,a,b) for(int i=a;i>=b;--i)

using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector VI;
typedef double db;

const int N = 2e5 + 5;

ll n, m, _, k;
ll a[N << 1];
ll ans, sum[N << 1], s[N];

int main()
{
ios::sync_with_stdio(0); cin.tie(0);
cin >> n >> m;
rep(i, 1, n) cin >> a[i], a[i + n] = a[i];
rep(i, 1, (n << 1))
{
sum[i] = sum[i - 1] + a[i];
if (i <= n) s[i] = s[i - 1] + (1 + a[i]) * a[i] / 2;
}

for (int l = 1, r = 1; l <= n; ++l)
{
    while (r < (n + l - 1) && sum[r] - sum[l - 1] < m) ++r;

    if (sum[r] - sum[l - 1] == m)
    {
        ll res;
        if (r > n) res = s[r - n] + s[n] - s[l - 1];
        else res = s[r] - s[l - 1];

        ans = max(ans, res);
    }
    else if (r != l)
    {
        ll res;
        if (r - 1 > n) res = s[r - 1 - n] + s[n] - s[l - 1];
        else res = s[r - 1] - s[l - 1];

        ll cnt = m - (sum[r - 1] - sum[l - 1]);
        ll ct = min(a[l], a[r] - cnt);

        ans = max(ans, res - (1 + ct) * (ct) / 2 + (1 + cnt + ct) * (cnt + ct) / 2);
    }
    else ans = max(ans, (a[r] - m + 1 + a[r]) * m / 2);
}
cout << ans;
return 0;

}

E

线段树,没调出来

猜你喜欢

转载自www.cnblogs.com/2aptx4869/p/12970080.html