Sun, 17 Nov 2019 10:28:36 +0800
parent
b315dfab80
commit
a3c173db6f
@ -0,0 +1,82 @@
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
#define CRP(t, x) const t &x
|
||||
#define OPX(op, t, x) operator op(CRP(t, x))
|
||||
#define OPL(t, x) bool OPX(<, t, x) const
|
||||
#define FIL(x, v) memset(x, v, sizeof(x))
|
||||
#define CLR(x) FIL(x, 0)
|
||||
#define NE1(x) FIL(x, -1)
|
||||
#define INF(x) FIL(x, 0x3f)
|
||||
#ifndef _DEBUG
|
||||
#define _DEBUG 0
|
||||
#endif // !_DEBUG
|
||||
#define IFD if (_DEBUG)
|
||||
typedef int64_t ll, i64;
|
||||
typedef uint64_t ull, u64;
|
||||
template <typename... Types>
|
||||
using comtype = typename common_type<Types...>::type;
|
||||
template <typename T>
|
||||
using enable_if_arithmetic = typename enable_if<is_arithmetic<T>::value>::type;
|
||||
template <typename T>
|
||||
using enable_if_integral = typename enable_if<is_integral<T>::value>::type;
|
||||
inline char getchar(int)
|
||||
{
|
||||
static char buf[64 << 20], *S = buf, *T = buf;
|
||||
if (S == T) T = fread(S = buf, 1, 64 << 20, stdin) + buf;
|
||||
return S == T ? EOF : *S++;
|
||||
}
|
||||
template <typename T, typename = enable_if_integral<T>>
|
||||
inline bool read(T &x)
|
||||
{
|
||||
int ch = x = 0, f = 1;
|
||||
while (!isdigit(ch = getchar()))
|
||||
if (ch == EOF)
|
||||
return false;
|
||||
else if (ch == '-')
|
||||
f = 0;
|
||||
for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
|
||||
return x = f ? x : -x, true;
|
||||
}
|
||||
template <typename T, typename... Args, typename = enable_if_integral<T>>
|
||||
inline bool read(T &x, Args &... args) { return read(x) && read(args...); }
|
||||
template <typename T1, typename T2, typename TResult = comtype<T1, T2>>
|
||||
inline TResult mmin(CRP(T1, v1), CRP(T2, v2)) { return min<TResult>(v1, v2); }
|
||||
template <typename T, typename... Args, typename TResult = comtype<T, Args...>>
|
||||
inline TResult mmin(CRP(T, v), const Args &... args) { return min<TResult>(v, mmin(args...)); }
|
||||
template <typename T1, typename T2, typename TResult = comtype<T1, T2>>
|
||||
inline TResult mmax(CRP(T1, v1), CRP(T2, v2)) { return max<TResult>(v1, v2); }
|
||||
template <typename T, typename... Args, typename TResult = comtype<T, Args...>>
|
||||
inline TResult mmax(CRP(T, v), const Args &... args) { return max<TResult>(v, mmax(args...)); }
|
||||
inline ll gcd(ll a, ll b)
|
||||
{
|
||||
for (; b; swap(a, b)) a = a % b;
|
||||
return a;
|
||||
}
|
||||
inline ll fpow(ll a, ll b, ll m)
|
||||
{
|
||||
ll r = 1;
|
||||
for (; b; b >>= 1, a = a * a % m)
|
||||
if (b & 1) r = r * a % m;
|
||||
return r;
|
||||
}
|
||||
constexpr double eps = 1e-8;
|
||||
inline int sgn(double x) { return x > eps ? 1 : x < -eps ? -1 : 0; }
|
||||
char s[220], t[220];
|
||||
int main()
|
||||
{
|
||||
scanf("%s%s", s, t);
|
||||
int n = strlen(s), m = strlen(t), ans = 0;
|
||||
for (int j = 0; j <= n; j++)
|
||||
for (int i = 0; i < j; i++)
|
||||
{
|
||||
int pos = 0;
|
||||
for (int p = 0; p < n; p++)
|
||||
if (p < i || p >= j)
|
||||
if (t[pos] == s[p]) pos++;
|
||||
if (pos >= m) ans = max(ans, j - i);
|
||||
}
|
||||
printf("%d", ans);
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,101 @@
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
#define CRP(t, x) const t &x
|
||||
#define OPX(op, t, x) operator op(CRP(t, x))
|
||||
#define OPL(t, x) bool OPX(<, t, x) const
|
||||
#define FIL(x, v) memset(x, v, sizeof(x))
|
||||
#define CLR(x) FIL(x, 0)
|
||||
#define NE1(x) FIL(x, -1)
|
||||
#define INF(x) FIL(x, 0x3f)
|
||||
#ifndef _DEBUG
|
||||
#define _DEBUG 0
|
||||
#endif // !_DEBUG
|
||||
#define IFD if (_DEBUG)
|
||||
typedef int64_t ll, i64;
|
||||
typedef uint64_t ull, u64;
|
||||
template <typename... Types>
|
||||
using comtype = typename common_type<Types...>::type;
|
||||
template <typename T>
|
||||
using enable_if_arithmetic = typename enable_if<is_arithmetic<T>::value>::type;
|
||||
template <typename T>
|
||||
using enable_if_integral = typename enable_if<is_integral<T>::value>::type;
|
||||
inline char getchar(int)
|
||||
{
|
||||
static char buf[64 << 20], *S = buf, *T = buf;
|
||||
if (S == T) T = fread(S = buf, 1, 64 << 20, stdin) + buf;
|
||||
return S == T ? EOF : *S++;
|
||||
}
|
||||
template <typename T, typename = enable_if_integral<T>>
|
||||
inline bool read(T &x)
|
||||
{
|
||||
int ch = x = 0, f = 1;
|
||||
while (!isdigit(ch = getchar()))
|
||||
if (ch == EOF)
|
||||
return false;
|
||||
else if (ch == '-')
|
||||
f = 0;
|
||||
for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
|
||||
return x = f ? x : -x, true;
|
||||
}
|
||||
template <typename T, typename... Args, typename = enable_if_integral<T>>
|
||||
inline bool read(T &x, Args &... args) { return read(x) && read(args...); }
|
||||
template <typename T1, typename T2, typename TResult = comtype<T1, T2>>
|
||||
inline TResult mmin(CRP(T1, v1), CRP(T2, v2)) { return min<TResult>(v1, v2); }
|
||||
template <typename T, typename... Args, typename TResult = comtype<T, Args...>>
|
||||
inline TResult mmin(CRP(T, v), const Args &... args) { return min<TResult>(v, mmin(args...)); }
|
||||
template <typename T1, typename T2, typename TResult = comtype<T1, T2>>
|
||||
inline TResult mmax(CRP(T1, v1), CRP(T2, v2)) { return max<TResult>(v1, v2); }
|
||||
template <typename T, typename... Args, typename TResult = comtype<T, Args...>>
|
||||
inline TResult mmax(CRP(T, v), const Args &... args) { return max<TResult>(v, mmax(args...)); }
|
||||
inline ll gcd(ll a, ll b)
|
||||
{
|
||||
for (; b; swap(a, b)) a = a % b;
|
||||
return a;
|
||||
}
|
||||
inline ll fpow(ll a, ll b, ll m)
|
||||
{
|
||||
ll r = 1;
|
||||
for (; b; b >>= 1, a = a * a % m)
|
||||
if (b & 1) r = r * a % m;
|
||||
return r;
|
||||
}
|
||||
constexpr double eps = 1e-8;
|
||||
inline int sgn(double x) { return x > eps ? 1 : x < -eps ? -1 : 0; }
|
||||
const int N = 2e5 + 50;
|
||||
char s[N], ans[N];
|
||||
int main()
|
||||
{
|
||||
int T, n;
|
||||
read(T);
|
||||
while (T--)
|
||||
{
|
||||
read(n), ans[n] = 0;
|
||||
scanf("%s", s);
|
||||
bool flag = true;
|
||||
for (char sp = '0'; sp <= '9' && flag; sp++)
|
||||
{
|
||||
int spl = find_if(s, s + n, bind(greater<char>(), placeholders::_1, sp)) - s;
|
||||
for (int i = 0; i < spl; i++) ans[i] = "21"[s[i] < sp];
|
||||
for (int i = spl; i < n; i++) ans[i] = "12"[s[i] > sp];
|
||||
bool can = true;
|
||||
int prev = '0';
|
||||
for (int i = 0; i < n && can; i++)
|
||||
if (ans[i] == '1')
|
||||
if (prev <= s[i])
|
||||
prev = s[i];
|
||||
else
|
||||
can = false;
|
||||
for (int i = 0; i < n && can; i++)
|
||||
if (ans[i] == '2')
|
||||
if (prev <= s[i])
|
||||
prev = s[i];
|
||||
else
|
||||
can = false;
|
||||
if (can) puts(ans), flag = false;
|
||||
}
|
||||
if (flag) puts("-");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,93 @@
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
#define CRP(t, x) const t &x
|
||||
#define OPX(op, t, x) operator op(CRP(t, x))
|
||||
#define OPL(t, x) bool OPX(<, t, x) const
|
||||
#define FIL(x, v) memset(x, v, sizeof(x))
|
||||
#define CLR(x) FIL(x, 0)
|
||||
#define NE1(x) FIL(x, -1)
|
||||
#define INF(x) FIL(x, 0x3f)
|
||||
#ifndef _DEBUG
|
||||
#define _DEBUG 0
|
||||
#endif // !_DEBUG
|
||||
#define IFD if (_DEBUG)
|
||||
typedef int64_t ll, i64;
|
||||
typedef uint64_t ull, u64;
|
||||
template <typename... Types>
|
||||
using comtype = typename common_type<Types...>::type;
|
||||
template <typename T>
|
||||
using enable_if_arithmetic = typename enable_if<is_arithmetic<T>::value>::type;
|
||||
template <typename T>
|
||||
using enable_if_integral = typename enable_if<is_integral<T>::value>::type;
|
||||
inline char getchar(int)
|
||||
{
|
||||
static char buf[64 << 20], *S = buf, *T = buf;
|
||||
if (S == T) T = fread(S = buf, 1, 64 << 20, stdin) + buf;
|
||||
return S == T ? EOF : *S++;
|
||||
}
|
||||
template <typename T, typename = enable_if_integral<T>>
|
||||
inline bool read(T &x)
|
||||
{
|
||||
int ch = x = 0, f = 1;
|
||||
while (!isdigit(ch = getchar()))
|
||||
if (ch == EOF)
|
||||
return false;
|
||||
else if (ch == '-')
|
||||
f = 0;
|
||||
for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
|
||||
return x = f ? x : -x, true;
|
||||
}
|
||||
template <typename T, typename... Args, typename = enable_if_integral<T>>
|
||||
inline bool read(T &x, Args &... args) { return read(x) && read(args...); }
|
||||
template <typename T1, typename T2, typename TResult = comtype<T1, T2>>
|
||||
inline TResult mmin(CRP(T1, v1), CRP(T2, v2)) { return min<TResult>(v1, v2); }
|
||||
template <typename T, typename... Args, typename TResult = comtype<T, Args...>>
|
||||
inline TResult mmin(CRP(T, v), const Args &... args) { return min<TResult>(v, mmin(args...)); }
|
||||
template <typename T1, typename T2, typename TResult = comtype<T1, T2>>
|
||||
inline TResult mmax(CRP(T1, v1), CRP(T2, v2)) { return max<TResult>(v1, v2); }
|
||||
template <typename T, typename... Args, typename TResult = comtype<T, Args...>>
|
||||
inline TResult mmax(CRP(T, v), const Args &... args) { return max<TResult>(v, mmax(args...)); }
|
||||
inline ll gcd(ll a, ll b)
|
||||
{
|
||||
for (; b; swap(a, b)) a = a % b;
|
||||
return a;
|
||||
}
|
||||
inline ll fpow(ll a, ll b, ll m)
|
||||
{
|
||||
ll r = 1;
|
||||
for (; b; b >>= 1, a = a * a % m)
|
||||
if (b & 1) r = r * a % m;
|
||||
return r;
|
||||
}
|
||||
constexpr double eps = 1e-8;
|
||||
inline int sgn(double x) { return x > eps ? 1 : x < -eps ? -1 : 0; }
|
||||
const int N = 2e5 + 50;
|
||||
struct Edge
|
||||
{
|
||||
int nxt, to;
|
||||
} E[N];
|
||||
int adj[N], ecnt, vis[N];
|
||||
inline void addEdge(int f, int t)
|
||||
{
|
||||
E[++ecnt] = {adj[f], t};
|
||||
adj[f] = ecnt;
|
||||
}
|
||||
void dfs(int x)
|
||||
{
|
||||
vis[x] = true;
|
||||
for (int e = adj[x]; e; e = E[e].nxt)
|
||||
if (!vis[E[e].to]) dfs(E[e].to);
|
||||
}
|
||||
int main()
|
||||
{
|
||||
int n, k;
|
||||
read(n, k);
|
||||
for (int i = 0, x, y; i < k; i++) read(x, y), addEdge(x, y), addEdge(y, x);
|
||||
int cnt = 0;
|
||||
for (int i = 1; i <= n; i++)
|
||||
if (!vis[i]) cnt++, dfs(i);
|
||||
printf("%d", max(0, k - (n - cnt)));
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,77 @@
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
#define CRP(t, x) const t &x
|
||||
#define OPX(op, t, x) operator op(CRP(t, x))
|
||||
#define OPL(t, x) bool OPX(<, t, x) const
|
||||
#define FIL(x, v) memset(x, v, sizeof(x))
|
||||
#define CLR(x) FIL(x, 0)
|
||||
#define NE1(x) FIL(x, -1)
|
||||
#define INF(x) FIL(x, 0x3f)
|
||||
#ifndef _DEBUG
|
||||
#define _DEBUG 0
|
||||
#endif // !_DEBUG
|
||||
#define IFD if (_DEBUG)
|
||||
typedef int64_t ll, i64;
|
||||
typedef uint64_t ull, u64;
|
||||
template <typename... Types>
|
||||
using comtype = typename common_type<Types...>::type;
|
||||
template <typename T>
|
||||
using enable_if_arithmetic = typename enable_if<is_arithmetic<T>::value>::type;
|
||||
template <typename T>
|
||||
using enable_if_integral = typename enable_if<is_integral<T>::value>::type;
|
||||
inline char getchar(int)
|
||||
{
|
||||
static char buf[64 << 20], *S = buf, *T = buf;
|
||||
if (S == T) T = fread(S = buf, 1, 64 << 20, stdin) + buf;
|
||||
return S == T ? EOF : *S++;
|
||||
}
|
||||
template <typename T, typename = enable_if_integral<T>>
|
||||
inline bool read(T &x)
|
||||
{
|
||||
int ch = x = 0, f = 1;
|
||||
while (!isdigit(ch = getchar()))
|
||||
if (ch == EOF)
|
||||
return false;
|
||||
else if (ch == '-')
|
||||
f = 0;
|
||||
for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
|
||||
return x = f ? x : -x, true;
|
||||
}
|
||||
template <typename T, typename... Args, typename = enable_if_integral<T>>
|
||||
inline bool read(T &x, Args &... args) { return read(x) && read(args...); }
|
||||
template <typename T1, typename T2, typename TResult = comtype<T1, T2>>
|
||||
inline TResult mmin(CRP(T1, v1), CRP(T2, v2)) { return min<TResult>(v1, v2); }
|
||||
template <typename T, typename... Args, typename TResult = comtype<T, Args...>>
|
||||
inline TResult mmin(CRP(T, v), const Args &... args) { return min<TResult>(v, mmin(args...)); }
|
||||
template <typename T1, typename T2, typename TResult = comtype<T1, T2>>
|
||||
inline TResult mmax(CRP(T1, v1), CRP(T2, v2)) { return max<TResult>(v1, v2); }
|
||||
template <typename T, typename... Args, typename TResult = comtype<T, Args...>>
|
||||
inline TResult mmax(CRP(T, v), const Args &... args) { return max<TResult>(v, mmax(args...)); }
|
||||
inline ll gcd(ll a, ll b)
|
||||
{
|
||||
for (; b; swap(a, b)) a = a % b;
|
||||
return a;
|
||||
}
|
||||
inline ll fpow(ll a, ll b, ll m)
|
||||
{
|
||||
ll r = 1;
|
||||
for (; b; b >>= 1, a = a * a % m)
|
||||
if (b & 1) r = r * a % m;
|
||||
return r;
|
||||
}
|
||||
constexpr double eps = 1e-8;
|
||||
inline int sgn(double x) { return x > eps ? 1 : x < -eps ? -1 : 0; }
|
||||
const int N = 1e5 + 50;
|
||||
constexpr int mod = 1e9 + 7;
|
||||
int f[N];
|
||||
int main()
|
||||
{
|
||||
f[0] = f[1] = 2;
|
||||
for (int i = 2; i < N; i++) f[i] = (f[i - 1] + f[i - 2]) % mod;
|
||||
int n, m;
|
||||
read(n, m);
|
||||
printf("%d", (f[n] + f[m] - 2u + mod) % mod);
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,92 @@
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
#define CRP(t, x) const t &x
|
||||
#define OPX(op, t, x) operator op(CRP(t, x))
|
||||
#define OPL(t, x) bool OPX(<, t, x) const
|
||||
#define FIL(x, v) memset(x, v, sizeof(x))
|
||||
#define CLR(x) FIL(x, 0)
|
||||
#define NE1(x) FIL(x, -1)
|
||||
#define INF(x) FIL(x, 0x3f)
|
||||
#ifndef _DEBUG
|
||||
#define _DEBUG 0
|
||||
#endif // !_DEBUG
|
||||
#define IFD if (_DEBUG)
|
||||
typedef int64_t ll, i64;
|
||||
typedef uint64_t ull, u64;
|
||||
template <typename... Types>
|
||||
using comtype = typename common_type<Types...>::type;
|
||||
template <typename T>
|
||||
using enable_if_arithmetic = typename enable_if<is_arithmetic<T>::value>::type;
|
||||
template <typename T>
|
||||
using enable_if_integral = typename enable_if<is_integral<T>::value>::type;
|
||||
inline char getchar(int)
|
||||
{
|
||||
static char buf[64 << 20], *S = buf, *T = buf;
|
||||
if (S == T) T = fread(S = buf, 1, 64 << 20, stdin) + buf;
|
||||
return S == T ? EOF : *S++;
|
||||
}
|
||||
template <typename T, typename = enable_if_integral<T>>
|
||||
inline bool read(T &x)
|
||||
{
|
||||
int ch = x = 0, f = 1;
|
||||
while (!isdigit(ch = getchar()))
|
||||
if (ch == EOF)
|
||||
return false;
|
||||
else if (ch == '-')
|
||||
f = 0;
|
||||
for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
|
||||
return x = f ? x : -x, true;
|
||||
}
|
||||
template <typename T, typename... Args, typename = enable_if_integral<T>>
|
||||
inline bool read(T &x, Args &... args) { return read(x) && read(args...); }
|
||||
template <typename T1, typename T2, typename TResult = comtype<T1, T2>>
|
||||
inline TResult mmin(CRP(T1, v1), CRP(T2, v2)) { return min<TResult>(v1, v2); }
|
||||
template <typename T, typename... Args, typename TResult = comtype<T, Args...>>
|
||||
inline TResult mmin(CRP(T, v), const Args &... args) { return min<TResult>(v, mmin(args...)); }
|
||||
template <typename T1, typename T2, typename TResult = comtype<T1, T2>>
|
||||
inline TResult mmax(CRP(T1, v1), CRP(T2, v2)) { return max<TResult>(v1, v2); }
|
||||
template <typename T, typename... Args, typename TResult = comtype<T, Args...>>
|
||||
inline TResult mmax(CRP(T, v), const Args &... args) { return max<TResult>(v, mmax(args...)); }
|
||||
inline ll gcd(ll a, ll b)
|
||||
{
|
||||
for (; b; swap(a, b)) a = a % b;
|
||||
return a;
|
||||
}
|
||||
inline ll fpow(ll a, ll b, ll m)
|
||||
{
|
||||
ll r = 1;
|
||||
for (; b; b >>= 1, a = a * a % m)
|
||||
if (b & 1) r = r * a % m;
|
||||
return r;
|
||||
}
|
||||
constexpr double eps = 1e-8;
|
||||
inline int sgn(double x) { return x > eps ? 1 : x < -eps ? -1 : 0; }
|
||||
const int N = 2e5 + 50;
|
||||
int a[N], p[N], s[N], mx[N];
|
||||
int main()
|
||||
{
|
||||
int T, n, m;
|
||||
read(T);
|
||||
while (T--)
|
||||
{
|
||||
read(n);
|
||||
memset(mx, 0, sizeof(int) * (n + 1));
|
||||
for (int i = 0; i < n; i++) read(a[i]);
|
||||
read(m);
|
||||
for (int i = 0; i < m; i++) read(p[i], s[i]), mx[s[i]] = max(mx[s[i]], p[i]);
|
||||
for (int i = n; i; i--) mx[i - 1] = max(mx[i - 1], mx[i]);
|
||||
int pos = 0, ans = 0;
|
||||
while (pos < n && ~ans)
|
||||
{
|
||||
ans++;
|
||||
int dis = 0;
|
||||
for (int curmax = 0; (curmax = max(curmax, a[pos + dis])) <= mx[dis + 1];) dis++;
|
||||
pos += dis;
|
||||
if (dis == 0) ans = -1;
|
||||
}
|
||||
printf("%d\n", ans);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -1,15 +1,15 @@
|
||||
#include <cstdio>
|
||||
using namespace std;
|
||||
char str[1024];
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
scanf("%d%s",&n,str);
|
||||
for(int i=1;i<n;i++)
|
||||
if(str[i-1]!=str[i]) {
|
||||
printf("YES %c%c",str[i-1],str[i]);
|
||||
return 0;
|
||||
}
|
||||
puts("NO");
|
||||
return 0;
|
||||
#include <cstdio>
|
||||
using namespace std;
|
||||
char str[1024];
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
scanf("%d%s",&n,str);
|
||||
for(int i=1;i<n;i++)
|
||||
if(str[i-1]!=str[i]) {
|
||||
printf("YES %c%c",str[i-1],str[i]);
|
||||
return 0;
|
||||
}
|
||||
puts("NO");
|
||||
return 0;
|
||||
}
|
||||
@ -1,34 +1,34 @@
|
||||
#include <cstdio>
|
||||
#include <set>
|
||||
#include <queue>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
scanf("%d",&n);
|
||||
queue<int> q;
|
||||
for(int i=0,x; i<n; i++)
|
||||
scanf("%d",&x),q.push(x);
|
||||
set<int> s;
|
||||
for(int i=0,x; i<n; i++)
|
||||
{
|
||||
scanf("%d",&x);
|
||||
if(s.count(x))
|
||||
printf("0 ");
|
||||
else
|
||||
{
|
||||
int sum=0,cur;
|
||||
do
|
||||
{
|
||||
cur=q.front();
|
||||
s.insert(q.front());
|
||||
q.pop();
|
||||
sum++;
|
||||
}
|
||||
while(cur!=x);
|
||||
printf("%d ",sum);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#include <cstdio>
|
||||
#include <set>
|
||||
#include <queue>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
scanf("%d",&n);
|
||||
queue<int> q;
|
||||
for(int i=0,x; i<n; i++)
|
||||
scanf("%d",&x),q.push(x);
|
||||
set<int> s;
|
||||
for(int i=0,x; i<n; i++)
|
||||
{
|
||||
scanf("%d",&x);
|
||||
if(s.count(x))
|
||||
printf("0 ");
|
||||
else
|
||||
{
|
||||
int sum=0,cur;
|
||||
do
|
||||
{
|
||||
cur=q.front();
|
||||
s.insert(q.front());
|
||||
q.pop();
|
||||
sum++;
|
||||
}
|
||||
while(cur!=x);
|
||||
printf("%d ",sum);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
add_executable("a" "a.cpp")
|
||||
add_executable("b" "b.cpp")
|
||||
add_executable("c" "c.cpp")
|
||||
add_executable("d" "d.cpp")
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
add_executable("a" "a.cpp")
|
||||
add_executable("b" "b.cpp")
|
||||
add_executable("c" "c.cpp")
|
||||
add_executable("d" "d.cpp")
|
||||
@ -1,20 +1,20 @@
|
||||
#include <cstdio>
|
||||
#include <algorithm>
|
||||
using namespace std;
|
||||
const int N = 2e5 + 20;
|
||||
char str[N];
|
||||
int main()
|
||||
{
|
||||
int n, flag = 1;
|
||||
scanf("%d%s", &n, str);
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
if (flag && str[i] > str[i + 1])
|
||||
{
|
||||
flag = 0;
|
||||
continue;
|
||||
}
|
||||
putchar(str[i]);
|
||||
}
|
||||
return 0;
|
||||
#include <cstdio>
|
||||
#include <algorithm>
|
||||
using namespace std;
|
||||
const int N = 2e5 + 20;
|
||||
char str[N];
|
||||
int main()
|
||||
{
|
||||
int n, flag = 1;
|
||||
scanf("%d%s", &n, str);
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
if (flag && str[i] > str[i + 1])
|
||||
{
|
||||
flag = 0;
|
||||
continue;
|
||||
}
|
||||
putchar(str[i]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -1,16 +1,16 @@
|
||||
#include <cstdio>
|
||||
#include <cmath>
|
||||
int main()
|
||||
{
|
||||
long long n, sum = 0;
|
||||
scanf("%lld", &n);
|
||||
long long lmt = sqrt(n) + 5;
|
||||
for (long long i = 2; i <= lmt; i++)
|
||||
if (n % i == 0)
|
||||
{
|
||||
sum = (n - i) / 2;
|
||||
break;
|
||||
}
|
||||
printf("%lld", sum + 1);
|
||||
return 0;
|
||||
#include <cstdio>
|
||||
#include <cmath>
|
||||
int main()
|
||||
{
|
||||
long long n, sum = 0;
|
||||
scanf("%lld", &n);
|
||||
long long lmt = sqrt(n) + 5;
|
||||
for (long long i = 2; i <= lmt; i++)
|
||||
if (n % i == 0)
|
||||
{
|
||||
sum = (n - i) / 2;
|
||||
break;
|
||||
}
|
||||
printf("%lld", sum + 1);
|
||||
return 0;
|
||||
}
|
||||
@ -1,23 +1,23 @@
|
||||
#include <cstdio>
|
||||
#include <cmath>
|
||||
using namespace std;
|
||||
int main()
|
||||
{
|
||||
int T, a;
|
||||
scanf("%d", &T);
|
||||
while (~scanf("%d", &a))
|
||||
{
|
||||
if (a == 0)
|
||||
printf("Y %.9lf %.9lf\n", 0, 0);
|
||||
else if (a == 1 || a == 2 || a == 3)
|
||||
puts("N");
|
||||
else
|
||||
{
|
||||
double d = a;
|
||||
double x = (d + sqrt(d - 4) * sqrt(d)) / 2;
|
||||
double y = (d - sqrt(d - 4) * sqrt(d)) / 2;
|
||||
printf("Y %.9lf %.9lf\n", x, y);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
#include <cstdio>
|
||||
#include <cmath>
|
||||
using namespace std;
|
||||
int main()
|
||||
{
|
||||
int T, a;
|
||||
scanf("%d", &T);
|
||||
while (~scanf("%d", &a))
|
||||
{
|
||||
if (a == 0)
|
||||
printf("Y %.9lf %.9lf\n", 0, 0);
|
||||
else if (a == 1 || a == 2 || a == 3)
|
||||
puts("N");
|
||||
else
|
||||
{
|
||||
double d = a;
|
||||
double x = (d + sqrt(d - 4) * sqrt(d)) / 2;
|
||||
double y = (d - sqrt(d - 4) * sqrt(d)) / 2;
|
||||
printf("Y %.9lf %.9lf\n", x, y);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -1,61 +1,61 @@
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <utility>
|
||||
#include <algorithm>
|
||||
using namespace std;
|
||||
const int N = 3e5 + 10, M = N << 1;
|
||||
int adj[N], ecnt = 1, dis[N];
|
||||
struct
|
||||
{
|
||||
int from, to, len, next, val;
|
||||
} E[M];
|
||||
inline void addEdge(int f, int t, int l)
|
||||
{
|
||||
ecnt++;
|
||||
E[ecnt].next = adj[f];
|
||||
E[ecnt].from = f;
|
||||
E[ecnt].len = l;
|
||||
E[ecnt].to = t;
|
||||
adj[f] = ecnt;
|
||||
}
|
||||
void spfa(int S)
|
||||
{
|
||||
static int q[N << 2];
|
||||
static bool inq[N];
|
||||
memset(inq, 0, sizeof(inq));
|
||||
int h = 0, t = 0;
|
||||
for (inq[q[t++] = S] = true; h ^ t; inq[h++] = false)
|
||||
for (int e = adj[q[h]]; e; e = E[e].next)
|
||||
if (dis[E[e].to] > dis[q[h]] + E[e].len)
|
||||
{
|
||||
dis[E[e].to] = dis[q[h]] + E[e].len;
|
||||
if (!inq[E[e].to]) inq[q[t++] = E[e].to] = true;
|
||||
}
|
||||
}
|
||||
pair<int, int> P[N];
|
||||
bool flg[N];
|
||||
int main()
|
||||
{
|
||||
int n, m, k;
|
||||
scanf("%d%d%d", &n, &m, &k);
|
||||
for (int i = 0, x, y, w; i < m; i++)
|
||||
{
|
||||
scanf("%d%d%d", &x, &y, &w);
|
||||
addEdge(x, y, w);
|
||||
addEdge(y, x, w);
|
||||
}
|
||||
spfa(1);
|
||||
for (int i = 1; i <= ecnt; i++)
|
||||
if (dis[E[i].from] == dis[E[i].to] + E[i].len)
|
||||
E[i].val++;
|
||||
for (int i = 2; i <= ecnt; i += 2)
|
||||
P[i >> 1].first = max(E[i].val, E[i + 1].val), P[i >> 1].second = (i >> 1);
|
||||
sort(P + 1, P + (ecnt >> 1) + 1);
|
||||
printf("%d\n", k);
|
||||
for (int i = 1; i <= m - k; i++)
|
||||
flg[P[i].second] = true;
|
||||
for (int i = 1; i <= m; i++)
|
||||
if (!flg[i])
|
||||
printf("%d ", i);
|
||||
return 0;
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <utility>
|
||||
#include <algorithm>
|
||||
using namespace std;
|
||||
const int N = 3e5 + 10, M = N << 1;
|
||||
int adj[N], ecnt = 1, dis[N];
|
||||
struct
|
||||
{
|
||||
int from, to, len, next, val;
|
||||
} E[M];
|
||||
inline void addEdge(int f, int t, int l)
|
||||
{
|
||||
ecnt++;
|
||||
E[ecnt].next = adj[f];
|
||||
E[ecnt].from = f;
|
||||
E[ecnt].len = l;
|
||||
E[ecnt].to = t;
|
||||
adj[f] = ecnt;
|
||||
}
|
||||
void spfa(int S)
|
||||
{
|
||||
static int q[N << 2];
|
||||
static bool inq[N];
|
||||
memset(inq, 0, sizeof(inq));
|
||||
int h = 0, t = 0;
|
||||
for (inq[q[t++] = S] = true; h ^ t; inq[h++] = false)
|
||||
for (int e = adj[q[h]]; e; e = E[e].next)
|
||||
if (dis[E[e].to] > dis[q[h]] + E[e].len)
|
||||
{
|
||||
dis[E[e].to] = dis[q[h]] + E[e].len;
|
||||
if (!inq[E[e].to]) inq[q[t++] = E[e].to] = true;
|
||||
}
|
||||
}
|
||||
pair<int, int> P[N];
|
||||
bool flg[N];
|
||||
int main()
|
||||
{
|
||||
int n, m, k;
|
||||
scanf("%d%d%d", &n, &m, &k);
|
||||
for (int i = 0, x, y, w; i < m; i++)
|
||||
{
|
||||
scanf("%d%d%d", &x, &y, &w);
|
||||
addEdge(x, y, w);
|
||||
addEdge(y, x, w);
|
||||
}
|
||||
spfa(1);
|
||||
for (int i = 1; i <= ecnt; i++)
|
||||
if (dis[E[i].from] == dis[E[i].to] + E[i].len)
|
||||
E[i].val++;
|
||||
for (int i = 2; i <= ecnt; i += 2)
|
||||
P[i >> 1].first = max(E[i].val, E[i + 1].val), P[i >> 1].second = (i >> 1);
|
||||
sort(P + 1, P + (ecnt >> 1) + 1);
|
||||
printf("%d\n", k);
|
||||
for (int i = 1; i <= m - k; i++)
|
||||
flg[P[i].second] = true;
|
||||
for (int i = 1; i <= m; i++)
|
||||
if (!flg[i])
|
||||
printf("%d ", i);
|
||||
return 0;
|
||||
}
|
||||
@ -1,16 +1,16 @@
|
||||
#include <cstdio>
|
||||
using namespace std;
|
||||
int main()
|
||||
{
|
||||
long long T, a, b, k;
|
||||
scanf("%lld", &T);
|
||||
while (T--)
|
||||
{
|
||||
scanf("%lld%lld%lld", &a, &b, &k);
|
||||
if (k & 1)
|
||||
printf("%lld\n", (a - b)*(k >> 1) + a);
|
||||
else
|
||||
printf("%lld\n", (a - b)*(k >> 1));
|
||||
}
|
||||
return 0;
|
||||
#include <cstdio>
|
||||
using namespace std;
|
||||
int main()
|
||||
{
|
||||
long long T, a, b, k;
|
||||
scanf("%lld", &T);
|
||||
while (T--)
|
||||
{
|
||||
scanf("%lld%lld%lld", &a, &b, &k);
|
||||
if (k & 1)
|
||||
printf("%lld\n", (a - b)*(k >> 1) + a);
|
||||
else
|
||||
printf("%lld\n", (a - b)*(k >> 1));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -1,17 +1,17 @@
|
||||
#include <cstdio>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
const int N = 2e5 + 20;
|
||||
int a[N];
|
||||
int main()
|
||||
{
|
||||
int n,ans=0;
|
||||
scanf("%d", &n);
|
||||
for (int i = 1; i <= n; i++)
|
||||
scanf("%d", a + i);
|
||||
for (int i = 1; i <= n; i++)
|
||||
if (a[i - 1] == 1 && a[i] == 0 && a[i + 1] == 1)a[i + 1] = 0, ans++;
|
||||
printf("%d", ans);
|
||||
return 0;
|
||||
#include <cstdio>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
const int N = 2e5 + 20;
|
||||
int a[N];
|
||||
int main()
|
||||
{
|
||||
int n,ans=0;
|
||||
scanf("%d", &n);
|
||||
for (int i = 1; i <= n; i++)
|
||||
scanf("%d", a + i);
|
||||
for (int i = 1; i <= n; i++)
|
||||
if (a[i - 1] == 1 && a[i] == 0 && a[i + 1] == 1)a[i + 1] = 0, ans++;
|
||||
printf("%d", ans);
|
||||
return 0;
|
||||
}
|
||||
@ -1,39 +1,39 @@
|
||||
#include <cstdio>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
using namespace std;
|
||||
typedef pair<int, int> pii;
|
||||
int main()
|
||||
{
|
||||
unordered_map<int, int>M;
|
||||
int n, k;
|
||||
scanf("%d%d", &n, &k);
|
||||
for (int i = 0, x; i < n; i++)
|
||||
scanf("%d", &x), M[x]++;
|
||||
auto cnt = vector<pii>(M.begin(), M.end());
|
||||
sort(cnt.begin(), cnt.end(), [](const pii&lhs, const pii&rhs) {
|
||||
return lhs.second > rhs.second;
|
||||
});
|
||||
int l = 1, r = n, m;
|
||||
while (l < r)
|
||||
{
|
||||
m = (l + r) >> 1;
|
||||
int len = 0;
|
||||
for (auto ite = cnt.begin(); ite != cnt.end(); ++ite)
|
||||
if (ite->second < m) break;
|
||||
else len += ite->second / m;
|
||||
if (len >= k)
|
||||
l = m + 1;
|
||||
else
|
||||
r = m;
|
||||
}
|
||||
vector<int>ans;
|
||||
for (auto ite = cnt.begin(); ite != cnt.end(); ++ite)
|
||||
if (ite->second < r) break;
|
||||
else for (int i = ite->second / r; i; i--)
|
||||
ans.push_back(ite->first);
|
||||
for (int i = 0; i < k; i++)
|
||||
printf("%d ", ans[i]);
|
||||
return 0;
|
||||
#include <cstdio>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
using namespace std;
|
||||
typedef pair<int, int> pii;
|
||||
int main()
|
||||
{
|
||||
unordered_map<int, int>M;
|
||||
int n, k;
|
||||
scanf("%d%d", &n, &k);
|
||||
for (int i = 0, x; i < n; i++)
|
||||
scanf("%d", &x), M[x]++;
|
||||
auto cnt = vector<pii>(M.begin(), M.end());
|
||||
sort(cnt.begin(), cnt.end(), [](const pii&lhs, const pii&rhs) {
|
||||
return lhs.second > rhs.second;
|
||||
});
|
||||
int l = 1, r = n, m;
|
||||
while (l < r)
|
||||
{
|
||||
m = (l + r) >> 1;
|
||||
int len = 0;
|
||||
for (auto ite = cnt.begin(); ite != cnt.end(); ++ite)
|
||||
if (ite->second < m) break;
|
||||
else len += ite->second / m;
|
||||
if (len >= k)
|
||||
l = m + 1;
|
||||
else
|
||||
r = m;
|
||||
}
|
||||
vector<int>ans;
|
||||
for (auto ite = cnt.begin(); ite != cnt.end(); ++ite)
|
||||
if (ite->second < r) break;
|
||||
else for (int i = ite->second / r; i; i--)
|
||||
ans.push_back(ite->first);
|
||||
for (int i = 0; i < k; i++)
|
||||
printf("%d ", ans[i]);
|
||||
return 0;
|
||||
}
|
||||
@ -1,31 +1,31 @@
|
||||
#include <cstdio>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
using namespace std;
|
||||
const int N = 2e5 + 10;
|
||||
int a[N];
|
||||
int main()
|
||||
{
|
||||
map<int, int> idx;
|
||||
int n;
|
||||
scanf("%d", &n);
|
||||
for (int i = 1; i <= n; i++)
|
||||
scanf("%d", a + i), idx[a[i]]++;
|
||||
vector<int> v;
|
||||
for (auto i : idx)v.push_back(i.second);
|
||||
long long add = 1, ans = 0, tmp, ty = 1;
|
||||
sort(v.begin(), v.end());
|
||||
for (int i = 0; i < v.size(); i++)
|
||||
for (; ty <= v[i]; ty++) {
|
||||
add = ty;
|
||||
tmp = add;
|
||||
add *= 2;
|
||||
for (int k = i + 1; k < v.size(); k++)
|
||||
if (v[k] >= add)
|
||||
tmp += add, add *= 2;
|
||||
ans = max(ans, tmp);
|
||||
}
|
||||
printf("%lld", ans);
|
||||
return 0;
|
||||
#include <cstdio>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
using namespace std;
|
||||
const int N = 2e5 + 10;
|
||||
int a[N];
|
||||
int main()
|
||||
{
|
||||
map<int, int> idx;
|
||||
int n;
|
||||
scanf("%d", &n);
|
||||
for (int i = 1; i <= n; i++)
|
||||
scanf("%d", a + i), idx[a[i]]++;
|
||||
vector<int> v;
|
||||
for (auto i : idx)v.push_back(i.second);
|
||||
long long add = 1, ans = 0, tmp, ty = 1;
|
||||
sort(v.begin(), v.end());
|
||||
for (int i = 0; i < v.size(); i++)
|
||||
for (; ty <= v[i]; ty++) {
|
||||
add = ty;
|
||||
tmp = add;
|
||||
add *= 2;
|
||||
for (int k = i + 1; k < v.size(); k++)
|
||||
if (v[k] >= add)
|
||||
tmp += add, add *= 2;
|
||||
ans = max(ans, tmp);
|
||||
}
|
||||
printf("%lld", ans);
|
||||
return 0;
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
add_executable(1 1.cpp)
|
||||
add_executable(2 2.cpp)
|
||||
add_executable(3 3.cpp)
|
||||
add_executable(4 4.cpp)
|
||||
add_executable(1 1.cpp)
|
||||
add_executable(2 2.cpp)
|
||||
add_executable(3 3.cpp)
|
||||
add_executable(4 4.cpp)
|
||||
add_executable(5 5.cpp)
|
||||
@ -0,0 +1,96 @@
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
#define CRP(t, x) const t &x
|
||||
#define OPX(op, t, x) operator op(CRP(t, x))
|
||||
#define OPL(t, x) bool OPX(<, t, x) const
|
||||
#define FIL(x, v) memset(x, v, sizeof(x))
|
||||
#define CLR(x) FIL(x, 0)
|
||||
#define NE1(x) FIL(x, -1)
|
||||
#define INF(x) FIL(x, 0x3f)
|
||||
#ifndef _DEBUG
|
||||
#define _DEBUG 0
|
||||
#endif // !_DEBUG
|
||||
#define IFD if (_DEBUG)
|
||||
typedef int64_t ll, i64;
|
||||
typedef uint64_t ull, u64;
|
||||
template <typename... Types>
|
||||
using comtype = typename common_type<Types...>::type;
|
||||
template <typename T>
|
||||
using enable_if_arithmetic = typename enable_if<is_arithmetic<T>::value>::type;
|
||||
template <typename T>
|
||||
using enable_if_integral = typename enable_if<is_integral<T>::value>::type;
|
||||
inline char getchar(int)
|
||||
{
|
||||
static char buf[64 << 20], *S = buf, *T = buf;
|
||||
if (S == T) T = fread(S = buf, 1, 64 << 20, stdin) + buf;
|
||||
return S == T ? EOF : *S++;
|
||||
}
|
||||
template <typename T, typename = enable_if_integral<T>>
|
||||
inline bool read(T &x)
|
||||
{
|
||||
int ch = x = 0, f = 1;
|
||||
while (!isdigit(ch = getchar()))
|
||||
if (ch == EOF)
|
||||
return false;
|
||||
else if (ch == '-')
|
||||
f = 0;
|
||||
for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
|
||||
return x = f ? x : -x, true;
|
||||
}
|
||||
template <typename T, typename... Args, typename = enable_if_integral<T>>
|
||||
inline bool read(T &x, Args &... args) { return read(x) && read(args...); }
|
||||
template <typename T1, typename T2, typename TResult = comtype<T1, T2>>
|
||||
inline TResult mmin(CRP(T1, v1), CRP(T2, v2)) { return min<TResult>(v1, v2); }
|
||||
template <typename T, typename... Args, typename TResult = comtype<T, Args...>>
|
||||
inline TResult mmin(CRP(T, v), const Args &... args) { return min<TResult>(v, mmin(args...)); }
|
||||
template <typename T1, typename T2, typename TResult = comtype<T1, T2>>
|
||||
inline TResult mmax(CRP(T1, v1), CRP(T2, v2)) { return max<TResult>(v1, v2); }
|
||||
template <typename T, typename... Args, typename TResult = comtype<T, Args...>>
|
||||
inline TResult mmax(CRP(T, v), const Args &... args) { return max<TResult>(v, mmax(args...)); }
|
||||
inline ll gcd(ll a, ll b)
|
||||
{
|
||||
for (; b; swap(a, b)) a %= b;
|
||||
return a;
|
||||
}
|
||||
inline ll fpow(ll a, ll b, ll m)
|
||||
{
|
||||
ll r = 1;
|
||||
for (; b; b >>= 1, a = a * a % m)
|
||||
if (b & 1) r = r * a % m;
|
||||
return r;
|
||||
}
|
||||
constexpr double eps = 1e-8;
|
||||
inline int sgn(double x) { return x > eps ? 1 : x < -eps ? -1 : 0; }
|
||||
const int N = 1e5 + 50;
|
||||
int a[N], b[N];
|
||||
int main()
|
||||
{
|
||||
int T, n;
|
||||
read(T);
|
||||
while (T--)
|
||||
{
|
||||
read(n);
|
||||
for (int i = 1; i <= n; i++) read(a[i]);
|
||||
for (int i = 1; i <= n; i++) read(b[i]);
|
||||
for (int i = 1; i <= n; i++) a[i] = b[i] - a[i];
|
||||
int cnt = 0;
|
||||
for (int i = 1; i <= n; i++)
|
||||
if (a[i] != a[i - 1]) cnt++;
|
||||
if (cnt == 0 && *a >= 0)
|
||||
puts("YES");
|
||||
else if (cnt > 2)
|
||||
puts("NO");
|
||||
else
|
||||
{
|
||||
auto p = minmax_element(a + 1, a + 1 + n);
|
||||
bool flag = *p.first >= 0;
|
||||
for (int i = 1; i <= n; i++)
|
||||
if (a[i] != 0 && a[i] != *p.second)
|
||||
flag = false;
|
||||
puts(flag ? "YES" : "NO");
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,98 @@
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
#define CRP(t, x) const t &x
|
||||
#define OPX(op, t, x) operator op(CRP(t, x))
|
||||
#define OPL(t, x) bool OPX(<, t, x) const
|
||||
#define FIL(x, v) memset(x, v, sizeof(x))
|
||||
#define CLR(x) FIL(x, 0)
|
||||
#define NE1(x) FIL(x, -1)
|
||||
#define INF(x) FIL(x, 0x3f)
|
||||
#ifndef _DEBUG
|
||||
#define _DEBUG 0
|
||||
#endif // !_DEBUG
|
||||
#define IFD if (_DEBUG)
|
||||
typedef int64_t ll, i64;
|
||||
typedef uint64_t ull, u64;
|
||||
template <typename... Types>
|
||||
using comtype = typename common_type<Types...>::type;
|
||||
template <typename T>
|
||||
using enable_if_arithmetic = typename enable_if<is_arithmetic<T>::value>::type;
|
||||
template <typename T>
|
||||
using enable_if_integral = typename enable_if<is_integral<T>::value>::type;
|
||||
inline char getchar(int)
|
||||
{
|
||||
static char buf[64 << 20], *S = buf, *T = buf;
|
||||
if (S == T) T = fread(S = buf, 1, 64 << 20, stdin) + buf;
|
||||
return S == T ? EOF : *S++;
|
||||
}
|
||||
template <typename T, typename = enable_if_integral<T>>
|
||||
inline bool read(T &x)
|
||||
{
|
||||
int ch = x = 0, f = 1;
|
||||
while (!isdigit(ch = getchar()))
|
||||
if (ch == EOF)
|
||||
return false;
|
||||
else if (ch == '-')
|
||||
f = 0;
|
||||
for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
|
||||
return x = f ? x : -x, true;
|
||||
}
|
||||
template <typename T, typename... Args, typename = enable_if_integral<T>>
|
||||
inline bool read(T &x, Args &... args) { return read(x) && read(args...); }
|
||||
template <typename T1, typename T2, typename TResult = comtype<T1, T2>>
|
||||
inline TResult mmin(CRP(T1, v1), CRP(T2, v2)) { return min<TResult>(v1, v2); }
|
||||
template <typename T, typename... Args, typename TResult = comtype<T, Args...>>
|
||||
inline TResult mmin(CRP(T, v), const Args &... args) { return min<TResult>(v, mmin(args...)); }
|
||||
template <typename T1, typename T2, typename TResult = comtype<T1, T2>>
|
||||
inline TResult mmax(CRP(T1, v1), CRP(T2, v2)) { return max<TResult>(v1, v2); }
|
||||
template <typename T, typename... Args, typename TResult = comtype<T, Args...>>
|
||||
inline TResult mmax(CRP(T, v), const Args &... args) { return max<TResult>(v, mmax(args...)); }
|
||||
inline ll gcd(ll a, ll b)
|
||||
{
|
||||
for (; b; swap(a, b)) a = a % b;
|
||||
return a;
|
||||
}
|
||||
inline ll fpow(ll a, ll b, ll m)
|
||||
{
|
||||
ll r = 1;
|
||||
for (; b; b >>= 1, a = a * a % m)
|
||||
if (b & 1) r = r * a % m;
|
||||
return r;
|
||||
}
|
||||
constexpr double eps = 1e-8;
|
||||
inline int sgn(double x) { return x > eps ? 1 : x < -eps ? -1 : 0; }
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
read(n);
|
||||
set<int> S, S2;
|
||||
vector<int> ans;
|
||||
for (int i = 0, cnt = 0, x; i < n; i++)
|
||||
{
|
||||
read(x), cnt++;
|
||||
if (x > 0)
|
||||
{
|
||||
if (S.count(x) || S2.count(x))
|
||||
return puts("-1"), 0;
|
||||
S.insert(x);
|
||||
S2.insert(x);
|
||||
}
|
||||
if (x < 0)
|
||||
{
|
||||
x = -x;
|
||||
if (!S.count(x)) return puts("-1"), 0;
|
||||
S.erase(x);
|
||||
if (S.empty()) ans.push_back(cnt), cnt = 0, S2.clear();
|
||||
}
|
||||
}
|
||||
if (S.empty())
|
||||
{
|
||||
cout << ans.size() << endl;
|
||||
for (int x : ans) cout << x << " ";
|
||||
}
|
||||
else
|
||||
puts("-1");
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,83 @@
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
#define CRP(t, x) const t &x
|
||||
#define OPX(op, t, x) operator op(CRP(t, x))
|
||||
#define OPL(t, x) bool OPX(<, t, x) const
|
||||
#define FIL(x, v) memset(x, v, sizeof(x))
|
||||
#define CLR(x) FIL(x, 0)
|
||||
#define NE1(x) FIL(x, -1)
|
||||
#define INF(x) FIL(x, 0x3f)
|
||||
#ifndef _DEBUG
|
||||
#define _DEBUG 0
|
||||
#endif // !_DEBUG
|
||||
#define IFD if (_DEBUG)
|
||||
typedef int64_t ll, i64;
|
||||
typedef uint64_t ull, u64;
|
||||
template <typename... Types>
|
||||
using comtype = typename common_type<Types...>::type;
|
||||
template <typename T>
|
||||
using enable_if_arithmetic = typename enable_if<is_arithmetic<T>::value>::type;
|
||||
template <typename T>
|
||||
using enable_if_integral = typename enable_if<is_integral<T>::value>::type;
|
||||
inline char getchar(int)
|
||||
{
|
||||
static char buf[64 << 20], *S = buf, *T = buf;
|
||||
if (S == T) T = fread(S = buf, 1, 64 << 20, stdin) + buf;
|
||||
return S == T ? EOF : *S++;
|
||||
}
|
||||
template <typename T, typename = enable_if_integral<T>>
|
||||
inline bool read(T &x)
|
||||
{
|
||||
int ch = x = 0, f = 1;
|
||||
while (!isdigit(ch = getchar()))
|
||||
if (ch == EOF)
|
||||
return false;
|
||||
else if (ch == '-')
|
||||
f = 0;
|
||||
for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
|
||||
return x = f ? x : -x, true;
|
||||
}
|
||||
template <typename T, typename... Args, typename = enable_if_integral<T>>
|
||||
inline bool read(T &x, Args &... args) { return read(x) && read(args...); }
|
||||
template <typename T1, typename T2, typename TResult = comtype<T1, T2>>
|
||||
inline TResult mmin(CRP(T1, v1), CRP(T2, v2)) { return min<TResult>(v1, v2); }
|
||||
template <typename T, typename... Args, typename TResult = comtype<T, Args...>>
|
||||
inline TResult mmin(CRP(T, v), const Args &... args) { return min<TResult>(v, mmin(args...)); }
|
||||
template <typename T1, typename T2, typename TResult = comtype<T1, T2>>
|
||||
inline TResult mmax(CRP(T1, v1), CRP(T2, v2)) { return max<TResult>(v1, v2); }
|
||||
template <typename T, typename... Args, typename TResult = comtype<T, Args...>>
|
||||
inline TResult mmax(CRP(T, v), const Args &... args) { return max<TResult>(v, mmax(args...)); }
|
||||
inline ll gcd(ll a, ll b)
|
||||
{
|
||||
for (; b; swap(a, b)) a = a % b;
|
||||
return a;
|
||||
}
|
||||
inline ll fpow(ll a, ll b, ll m)
|
||||
{
|
||||
ll r = 1;
|
||||
for (; b; b >>= 1, a = a * a % m)
|
||||
if (b & 1) r = r * a % m;
|
||||
return r;
|
||||
}
|
||||
constexpr double eps = 1e-8;
|
||||
inline int sgn(double x) { return x > eps ? 1 : x < -eps ? -1 : 0; }
|
||||
const int N = 2e5 + 50;
|
||||
ll a[N], dif[N];
|
||||
int main()
|
||||
{
|
||||
int m, n;
|
||||
read(n, m);
|
||||
for (int i = 0; i < n; i++) read(a[i]);
|
||||
sort(a, a + n);
|
||||
ll acc = 0;
|
||||
for (int i = 0, fac = 0; i < n; i++)
|
||||
{
|
||||
if (i % m == 0) fac++;
|
||||
dif[i - (fac - 1) * m] += a[i];
|
||||
acc += dif[i - (fac - 1) * m];
|
||||
printf("%lld ", acc);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
project(cf1253)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
if(MSVC)
|
||||
add_compile_options("/Zc:__cplusplus")
|
||||
endif()
|
||||
include_directories("D:\\PortableApps\\MSYS2\\mingw64\\include\\c++\\9.2.0\\x86_64-w64-mingw32")
|
||||
add_executable(A A.cpp)
|
||||
add_executable(B B.cpp)
|
||||
add_executable(C C.cpp)
|
||||
add_executable(D D.cpp)
|
||||
add_executable(E E.cpp)
|
||||
add_executable(F F.cpp)
|
||||
@ -0,0 +1,98 @@
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
#define CRP(t, x) const t &x
|
||||
#define OPX(op, t, x) operator op(CRP(t, x))
|
||||
#define OPL(t, x) bool OPX(<, t, x) const
|
||||
#define FIL(x, v) memset(x, v, sizeof(x))
|
||||
#define CLR(x) FIL(x, 0)
|
||||
#define NE1(x) FIL(x, -1)
|
||||
#define INF(x) FIL(x, 0x3f)
|
||||
#ifndef _DEBUG
|
||||
#define _DEBUG 0
|
||||
#endif // !_DEBUG
|
||||
#define IFD if (_DEBUG)
|
||||
typedef int64_t ll, i64;
|
||||
typedef uint64_t ull, u64;
|
||||
template <typename... Types>
|
||||
using comtype = typename common_type<Types...>::type;
|
||||
template <typename T>
|
||||
using enable_if_arithmetic = typename enable_if<is_arithmetic<T>::value>::type;
|
||||
template <typename T>
|
||||
using enable_if_integral = typename enable_if<is_integral<T>::value>::type;
|
||||
inline char getchar(int)
|
||||
{
|
||||
static char buf[64 << 20], *S = buf, *T = buf;
|
||||
if (S == T) T = fread(S = buf, 1, 64 << 20, stdin) + buf;
|
||||
return S == T ? EOF : *S++;
|
||||
}
|
||||
template <typename T, typename = enable_if_integral<T>>
|
||||
inline bool read(T &x)
|
||||
{
|
||||
int ch = x = 0, f = 1;
|
||||
while (!isdigit(ch = getchar()))
|
||||
if (ch == EOF)
|
||||
return false;
|
||||
else if (ch == '-')
|
||||
f = 0;
|
||||
for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
|
||||
return x = f ? x : -x, true;
|
||||
}
|
||||
template <typename T, typename... Args, typename = enable_if_integral<T>>
|
||||
inline bool read(T &x, Args &... args) { return read(x) && read(args...); }
|
||||
template <typename T1, typename T2, typename TResult = comtype<T1, T2>>
|
||||
inline TResult mmin(CRP(T1, v1), CRP(T2, v2)) { return min<TResult>(v1, v2); }
|
||||
template <typename T, typename... Args, typename TResult = comtype<T, Args...>>
|
||||
inline TResult mmin(CRP(T, v), const Args &... args) { return min<TResult>(v, mmin(args...)); }
|
||||
template <typename T1, typename T2, typename TResult = comtype<T1, T2>>
|
||||
inline TResult mmax(CRP(T1, v1), CRP(T2, v2)) { return max<TResult>(v1, v2); }
|
||||
template <typename T, typename... Args, typename TResult = comtype<T, Args...>>
|
||||
inline TResult mmax(CRP(T, v), const Args &... args) { return max<TResult>(v, mmax(args...)); }
|
||||
inline ll gcd(ll a, ll b)
|
||||
{
|
||||
for (; b; swap(a, b)) a = a % b;
|
||||
return a;
|
||||
}
|
||||
inline ll fpow(ll a, ll b, ll m)
|
||||
{
|
||||
ll r = 1;
|
||||
for (; b; b >>= 1, a = a * a % m)
|
||||
if (b & 1) r = r * a % m;
|
||||
return r;
|
||||
}
|
||||
constexpr double eps = 1e-8;
|
||||
inline int sgn(double x) { return x > eps ? 1 : x < -eps ? -1 : 0; }
|
||||
const int N = 4e5 + 50;
|
||||
int fa[N];
|
||||
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
|
||||
int main()
|
||||
{
|
||||
int n, m;
|
||||
read(n, m);
|
||||
for (int i = 0; i <= n; i++) fa[i] = i;
|
||||
for (int i = 0, x, y; i < m; i++) read(x, y), fa[find(x)] = find(y);
|
||||
int grps = 0;
|
||||
for (int i = 1; i <= n; i++) grps = max(grps, find(i));
|
||||
vector<vector<int>> v(grps + 1);
|
||||
for (int i = 1; i <= n; i++) v[find(i)].push_back(i);
|
||||
int ans = 0;
|
||||
set<int> S;
|
||||
for (int i = 1; i <= n; i++) S.insert(i);
|
||||
while (!S.empty())
|
||||
{
|
||||
int curmin = *S.begin();
|
||||
int ty = find(curmin);
|
||||
int curmax = *v[ty].rbegin();
|
||||
for (int i = curmin + 1; i < curmax; i++)
|
||||
{
|
||||
if (find(i) != ty)
|
||||
ans++, curmax = max(curmax, *v[find(i)].rbegin()), fa[find(i)] = ty;
|
||||
S.erase(i);
|
||||
}
|
||||
S.erase(curmin);
|
||||
S.erase(curmax);
|
||||
}
|
||||
printf("%d", ans);
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,69 @@
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
#define CRP(t, x) const t &x
|
||||
#define OPX(op, t, x) operator op(CRP(t, x))
|
||||
#define OPL(t, x) bool OPX(<, t, x) const
|
||||
#define FIL(x, v) memset(x, v, sizeof(x))
|
||||
#define CLR(x) FIL(x, 0)
|
||||
#define NE1(x) FIL(x, -1)
|
||||
#define INF(x) FIL(x, 0x3f)
|
||||
#ifndef _DEBUG
|
||||
#define _DEBUG 0
|
||||
#endif // !_DEBUG
|
||||
#define IFD if (_DEBUG)
|
||||
typedef int64_t ll, i64;
|
||||
typedef uint64_t ull, u64;
|
||||
template <typename... Types>
|
||||
using comtype = typename common_type<Types...>::type;
|
||||
template <typename T>
|
||||
using enable_if_arithmetic = typename enable_if<is_arithmetic<T>::value>::type;
|
||||
template <typename T>
|
||||
using enable_if_integral = typename enable_if<is_integral<T>::value>::type;
|
||||
inline char getchar(int)
|
||||
{
|
||||
static char buf[64 << 20], *S = buf, *T = buf;
|
||||
if (S == T) T = fread(S = buf, 1, 64 << 20, stdin) + buf;
|
||||
return S == T ? EOF : *S++;
|
||||
}
|
||||
template <typename T, typename = enable_if_integral<T>>
|
||||
inline bool read(T &x)
|
||||
{
|
||||
int ch = x = 0, f = 1;
|
||||
while (!isdigit(ch = getchar()))
|
||||
if (ch == EOF)
|
||||
return false;
|
||||
else if (ch == '-')
|
||||
f = 0;
|
||||
for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
|
||||
return x = f ? x : -x, true;
|
||||
}
|
||||
template <typename T, typename... Args, typename = enable_if_integral<T>>
|
||||
inline bool read(T &x, Args &... args) { return read(x) && read(args...); }
|
||||
template <typename T1, typename T2, typename TResult = comtype<T1, T2>>
|
||||
inline TResult mmin(CRP(T1, v1), CRP(T2, v2)) { return min<TResult>(v1, v2); }
|
||||
template <typename T, typename... Args, typename TResult = comtype<T, Args...>>
|
||||
inline TResult mmin(CRP(T, v), const Args &... args) { return min<TResult>(v, mmin(args...)); }
|
||||
template <typename T1, typename T2, typename TResult = comtype<T1, T2>>
|
||||
inline TResult mmax(CRP(T1, v1), CRP(T2, v2)) { return max<TResult>(v1, v2); }
|
||||
template <typename T, typename... Args, typename TResult = comtype<T, Args...>>
|
||||
inline TResult mmax(CRP(T, v), const Args &... args) { return max<TResult>(v, mmax(args...)); }
|
||||
inline ll gcd(ll a, ll b)
|
||||
{
|
||||
for (; b; swap(a, b)) a = a % b;
|
||||
return a;
|
||||
}
|
||||
inline ll fpow(ll a, ll b, ll m)
|
||||
{
|
||||
ll r = 1;
|
||||
for (; b; b >>= 1, a = a * a % m)
|
||||
if (b & 1) r = r * a % m;
|
||||
return r;
|
||||
}
|
||||
constexpr double eps = 1e-8;
|
||||
inline int sgn(double x) { return x > eps ? 1 : x < -eps ? -1 : 0; }
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,69 @@
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
#define CRP(t, x) const t &x
|
||||
#define OPX(op, t, x) operator op(CRP(t, x))
|
||||
#define OPL(t, x) bool OPX(<, t, x) const
|
||||
#define FIL(x, v) memset(x, v, sizeof(x))
|
||||
#define CLR(x) FIL(x, 0)
|
||||
#define NE1(x) FIL(x, -1)
|
||||
#define INF(x) FIL(x, 0x3f)
|
||||
#ifndef _DEBUG
|
||||
#define _DEBUG 0
|
||||
#endif // !_DEBUG
|
||||
#define IFD if (_DEBUG)
|
||||
typedef int64_t ll, i64;
|
||||
typedef uint64_t ull, u64;
|
||||
template <typename... Types>
|
||||
using comtype = typename common_type<Types...>::type;
|
||||
template <typename T>
|
||||
using enable_if_arithmetic = typename enable_if<is_arithmetic<T>::value>::type;
|
||||
template <typename T>
|
||||
using enable_if_integral = typename enable_if<is_integral<T>::value>::type;
|
||||
inline char getchar(int)
|
||||
{
|
||||
static char buf[64 << 20], *S = buf, *T = buf;
|
||||
if (S == T) T = fread(S = buf, 1, 64 << 20, stdin) + buf;
|
||||
return S == T ? EOF : *S++;
|
||||
}
|
||||
template <typename T, typename = enable_if_integral<T>>
|
||||
inline bool read(T &x)
|
||||
{
|
||||
int ch = x = 0, f = 1;
|
||||
while (!isdigit(ch = getchar()))
|
||||
if (ch == EOF)
|
||||
return false;
|
||||
else if (ch == '-')
|
||||
f = 0;
|
||||
for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
|
||||
return x = f ? x : -x, true;
|
||||
}
|
||||
template <typename T, typename... Args, typename = enable_if_integral<T>>
|
||||
inline bool read(T &x, Args &... args) { return read(x) && read(args...); }
|
||||
template <typename T1, typename T2, typename TResult = comtype<T1, T2>>
|
||||
inline TResult mmin(CRP(T1, v1), CRP(T2, v2)) { return min<TResult>(v1, v2); }
|
||||
template <typename T, typename... Args, typename TResult = comtype<T, Args...>>
|
||||
inline TResult mmin(CRP(T, v), const Args &... args) { return min<TResult>(v, mmin(args...)); }
|
||||
template <typename T1, typename T2, typename TResult = comtype<T1, T2>>
|
||||
inline TResult mmax(CRP(T1, v1), CRP(T2, v2)) { return max<TResult>(v1, v2); }
|
||||
template <typename T, typename... Args, typename TResult = comtype<T, Args...>>
|
||||
inline TResult mmax(CRP(T, v), const Args &... args) { return max<TResult>(v, mmax(args...)); }
|
||||
inline ll gcd(ll a, ll b)
|
||||
{
|
||||
for (; b; swap(a, b)) a = a % b;
|
||||
return a;
|
||||
}
|
||||
inline ll fpow(ll a, ll b, ll m)
|
||||
{
|
||||
ll r = 1;
|
||||
for (; b; b >>= 1, a = a * a % m)
|
||||
if (b & 1) r = r * a % m;
|
||||
return r;
|
||||
}
|
||||
constexpr double eps = 1e-8;
|
||||
inline int sgn(double x) { return x > eps ? 1 : x < -eps ? -1 : 0; }
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in new issue