B - Unique Nicknames
#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
#define int long long
typedef long long LL;
typedef long long ll;
const int INF = 0x3f3f3f3f;
//const int inf = 1e18;
const int mod = 998244353;
//const int mod = 1e9 + 7;
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }
const int maxn = 1e2 + 10;
const int N = 6e6 + 100;
int dp[maxn][maxn][maxn][maxn];
int a[maxn][maxn];
int v[maxn];
map<string,int> mp;
string s[101];
string t[101];
void solve() {
int n;
cin>>n;
for (int i = 0; i < n; ++i) {
cin>>s[i]>>t[i];
mp[s[i]]++,mp[t[i]]++;
if(s[i]==t[i]) mp[s[i]]--;
}
for (int i = 0; i < n; ++i) {
if(mp[s[i]]>1&&mp[t[i]]>1){
cout<<"No"<<endl;
return;
}
}
cout<<"Yes"<<endl;
}
signed main() {
//ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int _ = 1;
// cin >> _;
while (_--) {
solve();//cout<<"\n";
}
return 0;
}
//12341
//14321
//
C - 1 2 1 3 1 2 1
#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
#define int long long
typedef long long LL;
typedef long long ll;
const int INF = 0x3f3f3f3f;
//const int inf = 1e18;
const int mod = 998244353;
//const int mod = 1e9 + 7;
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }
const int maxn = 1e2 + 10;
const int N = 6e6 + 100;
int dp[maxn][maxn][maxn][maxn];
int a[maxn][maxn];
int v[maxn];
map<string,int> mp;
string s[101];
string t[101];
void dfs(int n){
if(n<1) return;
dfs(n-1);
cout<<n<<" ";
dfs(n-1);
}
void solve() {
int n;
cin>>n;
dfs(n);
}
signed main() {
//ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int _ = 1;
// cin >> _;
while (_--) {
solve();//cout<<"\n";
}
return 0;
}
//12341
//14321
//
D - Cylinder
#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
#define int long long
typedef long long LL;
typedef long long ll;
const int INF = 0x3f3f3f3f;
//const int inf = 1e18;
const int mod = 998244353;
//const int mod = 1e9 + 7;
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }
const int maxn = 1e2 + 10;
const int N = 6e6 + 100;
int dp[maxn][maxn][maxn][maxn];
int a[maxn][maxn];
int v[maxn];
queue<pair<int,int>> que;
void solve() {
int n;
cin>>n;
while (n--){
int t,x,c;
cin>>t;
if(t==1){
cin>>x>>c;
que.push({c,x});
}else{
cin>>c;
int sum=0;
while (c>0){
auto &[cc,xx] = que.front();
sum+=min(cc,c)*xx;
c-=cc,cc=-c;
if(cc<0) que.pop();
}
cout<<sum<<endl;
}
}
}
signed main() {
//ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int _ = 1;
// cin >> _;
while (_--) {
solve();//cout<<"\n";
}
return 0;
}
//12341
//14321
//
E - Max Min
容斥
#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
#define int long long
typedef long long LL;
typedef long long ll;
const int INF = 0x3f3f3f3f;
//const int inf = 1e18;
const int mod = 998244353;
//const int mod = 1e9 + 7;
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }
const int maxn = 1e6 + 10;
const int N = 6e6 + 100;
int dp[maxn];
int a[maxn];
int v[maxn];
int n,y,x;
int getNum(int l,int r){
int res=0,len=0;
for (int i = 0; i < n; ++i) {
if(a[i]<l||a[i]>r){
res+=(len+1)*len/2;
len=0;
} else{
len++;
}
}
if(len) res+=(len+1)*len/2;
return res;
}
void solve() {
cin>>n>>x>>y;
for (int i = 0; i < n; ++i) {
cin>>a[i];
}
cout<<getNum(y,x)-getNum(y+1,x)-getNum(y,x-1)+getNum(y+1,x-1)<<endl;
}
signed main() {
//ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int _ = 1;
// cin >> _;
while (_--) {
solve();//cout<<"\n";
}
return 0;
}
//12341
//14321
//
dp
#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
#define int long long
typedef long long LL;
typedef long long ll;
const int INF = 0x3f3f3f3f;
//const int inf = 1e18;
const int mod = 998244353;
//const int mod = 1e9 + 7;
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }
const int maxn = 1e6 + 10;
const int N = 6e6 + 100;
int dp[maxn][3][3];
int a[maxn];
int v[maxn];
int n,y,x;
void solve() {
cin>>n>>x>>y;
int ans=0;
for (int i = 1; i <=n; ++i) {
cin>>a[i];
}
for (int i = 1; i <=n; ++i) {
if(a[i]<y||a[i]>x) continue;
int l=a[i]==y,r=a[i]==x;
dp[i][l][r]+=1;
for (int j = 0; j < 2; ++j) {
for (int k = 0; k < 2; ++k) {
dp[i][l|j][r|k]+=dp[i-1][j][k];
}
}
ans+=dp[i][1][1];
}
cout<<ans;
}
signed main() {
//ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int _ = 1;
// cin >> _;
while (_--) {
solve();//cout<<"\n";
}
return 0;
}
//12341
//14321
//