codeforces964(A~G2)

A.A+B Again?


#include <bits/stdc++.h>
using namespace std;
#define lll __int128
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> PII;
const int mod = 1e9 + 7;
inline ll read()
{
   ll x = 0, y = 1;
   char c = getchar();
   while (!isdigit(c))
   {
      if (c == '-')
         y = -1;
      c = getchar();
   }
   while (isdigit(c))
   {
      x = (x << 3) + (x << 1) + (c ^ 48);
      c = getchar();
   }
   return x *= y;
}
inline void write(ll x)
{
   if (x < 0)
      x = -x, putchar('-');
   ll sta[35], top = 0;
   do
      sta[top++] = x % 10, x /= 10;
   while (x);
   while (top)
      putchar(sta[--top] + '0');
}



void Miraitowa()
{
   string s;
   cin >> s;
   cout << s[0]-'0' + s[1]-'0' << endl;
}

int main()
{
   ios::sync_with_stdio(false);
   cin.tie(0), cout.tie(0);
   int t;
   cin>>t;
   while(t--)
   Miraitowa();
   return 0;
};

B.Card Game


#include <bits/stdc++.h>
using namespace std;
#define lll __int128
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> PII;
const int mod = 1e9 + 7;
inline ll read()
{
   ll x = 0, y = 1;
   char c = getchar();
   while (!isdigit(c))
   {
      if (c == '-')
         y = -1;
      c = getchar();
   }
   while (isdigit(c))
   {
      x = (x << 3) + (x << 1) + (c ^ 48);
      c = getchar();
   }
   return x *= y;
}
inline void write(ll x)
{
   if (x < 0)
      x = -x, putchar('-');
   ll sta[35], top = 0;
   do
      sta[top++] = x % 10, x /= 10;
   while (x);
   while (top)
      putchar(sta[--top] + '0');
}



void Miraitowa()
{
   ll a1, a2, b1, b2;
   ll cnt = 0;
   cin >> a1 >> a2 >> b1 >> b2;
   int cnt1 = 0, cnt2 = 0;
   if(a1>b1) cnt1++;
   else if(a1<b1) cnt2++;
   if(a2>b2)  cnt1++;
   else  if(a2<b2)cnt2++;
    if(cnt1>cnt2)  cnt++;
    cnt1 = 0, cnt2 = 0;
    if (a1 > b2)   cnt1++;
    else if(a1<b2)   cnt2++;
    if (a2 > b1) cnt1++;
    else if(a2<b1)   cnt2++;
    if (cnt1 > cnt2) cnt++;
    cout << 2 * cnt << endl;
}

int main()
{
   ios::sync_with_stdio(false);
   cin.tie(0), cout.tie(0);
   int t;
   cin>>t;
   while(t--)
   Miraitowa();
   return 0;
};

C.Showering


#include <bits/stdc++.h>
using namespace std;
#define lll __int128
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> PII;
const int mod = 1e9 + 7;
inline ll read()
{
   ll x = 0, y = 1;
   char c = getchar();
   while (!isdigit(c))
   {
      if (c == '-')
         y = -1;
      c = getchar();
   }
   while (isdigit(c))
   {
      x = (x << 3) + (x << 1) + (c ^ 48);
      c = getchar();
   }
   return x *= y;
}
inline void write(ll x)
{
   if (x < 0)
      x = -x, putchar('-');
   ll sta[35], top = 0;
   do
      sta[top++] = x % 10, x /= 10;
   while (x);
   while (top)
      putchar(sta[--top] + '0');
}

const int N = 3e5 + 10;
PII a[N];

void Miraitowa()
{
   ll n, s, m;
   cin >> n >> s >> m;
   for (int i = 1; i <= n; i++)
      cin >> a[i].first >> a[i].second;

   sort(a + 1, a + 1 + n);

   ll res = 0, j = 0;
   for (int i = 1; i <= n; i++)
      res = max(res, a[i].first - j), j = a[i].second;
   res = max(res, m - a[n].second);

   if (res >= s)
      cout << "Yes" << endl;
   else
      cout << "No" << endl;
}

int main()
{
   ios::sync_with_stdio(false);
   cin.tie(0), cout.tie(0);
   int t;
   cin >> t;
   while (t--)
      Miraitowa();
   return 0;
};

D.Slavic’s Exam


#include <bits/stdc++.h>
using namespace std;
#define lll __int128
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> PII;
const int mod = 1e9 + 7;
inline ll read()
{
   ll x = 0, y = 1;
   char c = getchar();
   while (!isdigit(c))
   {
      if (c == '-')
         y = -1;
      c = getchar();
   }
   while (isdigit(c))
   {
      x = (x << 3) + (x << 1) + (c ^ 48);
      c = getchar();
   }
   return x *= y;
}
inline void write(ll x)
{
   if (x < 0)
      x = -x, putchar('-');
   ll sta[35], top = 0;
   do
      sta[top++] = x % 10, x /= 10;
   while (x);
   while (top)
      putchar(sta[--top] + '0');
}

const int N = 3e5 + 10;
PII a[N];

void Miraitowa()
{
   string s, t;
   cin >> s >> t;
   int cnt = 0;

   for (int i = 0; i < s.size();i++){
        if(cnt>=t.size())    continue;
        if (s[i] == t[cnt])     cnt++;
          else{
             if(s[i]=='?')     s[i] = t[cnt], cnt++;
          }
   }

   for (int i = 0; i < s.size();i++)
       if(s[i]=='?')    s[i] = 'a';

       if(cnt>=t.size()){
          cout << "YES" << endl;
          cout << s << endl;
       }else     cout << "NO" << endl;
}

int main()
{
   ios::sync_with_stdio(false);
   cin.tie(0), cout.tie(0);
   int t;
   cin >> t;
   while (t--)
      Miraitowa();
   return 0;
};

E.Triple Operations


#include<bits/stdc++.h>
using namespace std;
#define lll __int128
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> PII;
const int mod=1e9+7;
inline ll read()
{
   ll x = 0, y = 1;
   char c = getchar();
   while (!isdigit(c))
   {
      if (c == '-')
         y = -1;
      c = getchar();
   }
   while (isdigit(c))
   {
      x = (x << 3) + (x << 1) + (c ^ 48);
      c = getchar();
   }
   return x *= y;
}
inline void write(ll x)
{
   if (x < 0)
      x = -x, putchar('-');
   ll sta[35], top = 0;
   do
      sta[top++] = x % 10, x /= 10;
   while (x);
   while (top)
      putchar(sta[--top] + '0');
}

const int N=3e5+10;
ll a[N];

void Miraitowa(){
   int l, r;
   cin >> l >> r;
   cout << a[r] - a[l - 1] + a[l] - a[l - 1] << endl;
}


int main(){
 ios::sync_with_stdio(false);
 cin.tie(0),cout.tie(0);

 for (int i = 1; i < N;i++){
    int x = i, cnt = 0;
    while(x)  x /= 3, cnt++;
    a[i] = cnt;
 }

 for (int i = 1; i < N;i++)
    a[i] += a[i - 1];

    int t;
 cin >> t;
 while (t--)
    Miraitowa();
 return 0;
};


F.Expected Median


#include<bits/stdc++.h>
using namespace std;
#define lll __int128
#define endl '\n'
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> PII;
const int mod=1e9+7;
inline ll read()
{
   ll x = 0, y = 1;
   char c = getchar();
   while (!isdigit(c))
   {
      if (c == '-')
         y = -1;
      c = getchar();
   }
   while (isdigit(c))
   {
      x = (x << 3) + (x << 1) + (c ^ 48);
      c = getchar();
   }
   return x *= y;
}
inline void write(ll x)
{
   if (x < 0)
      x = -x, putchar('-');
   ll sta[35], top = 0;
   do
      sta[top++] = x % 10, x /= 10;
   while (x);
   while (top)
      putchar(sta[--top] + '0');
}

const int N = 3e5 + 10;
ll fact[N], infact[N];

ll qmi(ll a,ll b){
   ll res = 1;
   while(b){
          if(b&1)   res = res * a % mod;
          b >>= 1;
          a = a * a % mod;
   }
   return res;
}
ll C(ll a,ll b){
   return fact[a] * infact[b] % mod * infact[a - b] % mod;
}




void Miraitowa(){
   ll cnt1=0, cnt2=0;
   ll n, k;
   cin >> n >> k;
   for (int i = 1; i <= n;i++){
      ll x;
      cin >> x;
      if(x==1)  cnt1++;
      else  cnt2++;
   }


   ll res = 0;
   for (int i = k / 2 + 1; i <= k;i++){
      int j = k - i;
      if(i>cnt1)   continue;
      if(j>cnt2)    continue;
   res=(res+C(cnt1,i)*C(cnt2,j)%mod)%mod;   
   }
   cout << res << endl;
}


int main(){
 ios::sync_with_stdio(false);
 cin.tie(0),cout.tie(0);

 fact[0] = infact[0] = 1;

 for (int i = 1; i < N;i++){
    fact[i] = fact[i - 1] * i % mod;
    infact[i] = infact[i - 1] * qmi(i, mod - 2) % mod;
 }

    int t;
 cin >> t;
 while (t--)
    Miraitowa();
 return 0;
};


G1.Ruler (easy version)


#include <bits/stdc++.h>
using namespace std;
#define lll __int128
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> PII;
const int mod = 1e9 + 7;
inline ll read()
{
   ll x = 0, y = 1;
   char c = getchar();
   while (!isdigit(c))
   {
      if (c == '-')
         y = -1;
      c = getchar();
   }
   while (isdigit(c))
   {
      x = (x << 3) + (x << 1) + (c ^ 48);
      c = getchar();
   }
   return x *= y;
}
inline void write(ll x)
{
   if (x < 0)
      x = -x, putchar('-');
   ll sta[35], top = 0;
   do
      sta[top++] = x % 10, x /= 10;
   while (x);
   while (top)
      putchar(sta[--top] + '0');
}

ll query(ll a, ll b)
{
   std::cout << "? " << a << " " << b << std::endl;
   int res;
   std::cin >> res;
   return res;
}

void solve()
{
   ll lo = 2, hi = 999;
   while (lo < hi)
   {
      ll x = (lo + hi) / 2;
      if (query(1, x) == x + 1)
      {
         hi = x;
      }
      else
      {
         lo = x + 1;
      }
   }
   std::cout << "! " << lo << std::endl;
}

int main()
{
   ios::sync_with_stdio(false);
   cin.tie(0), cout.tie(0);

   int t;
   cin >> t;
   while (t--)
      solve();
   return 0;
};

G2.Ruler (hard version)


#include <bits/stdc++.h>
using namespace std;
#define lll __int128
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> PII;
const int mod = 1e9 + 7;
inline ll read()
{
   ll x = 0, y = 1;
   char c = getchar();
   while (!isdigit(c))
   {
      if (c == '-')
         y = -1;
      c = getchar();
   }
   while (isdigit(c))
   {
      x = (x << 3) + (x << 1) + (c ^ 48);
      c = getchar();
   }
   return x *= y;
}
inline void write(ll x)
{
   if (x < 0)
      x = -x, putchar('-');
   ll sta[35], top = 0;
   do
      sta[top++] = x % 10, x /= 10;
   while (x);
   while (top)
      putchar(sta[--top] + '0');
}

int query(int a, int b)
{
   std::cout << "? " << a << " " << b << std::endl;
   int res;
   std::cin >> res;
   return res;
}

void solve()
{
   int lo = 1, hi = 999;
   while (hi - lo > 1)
   {
      int x = lo + (hi - lo) / 3;
      int y = lo + (hi - lo) * 2 / 3;
      int res = query(x, y);
      if (res == x * y)
      {
         lo = y;
      }
      else if (res == x * (y + 1))
      {
         lo = x;
         hi = y;
      }
      else
      {
         assert(res == (x + 1) * (y + 1));
         hi = x;
      }
   }
   std::cout << "! " << hi << std::endl;
}

int main()
{
   ios::sync_with_stdio(false);
   cin.tie(0), cout.tie(0);

   int t;
   cin >> t;
   while (t--)
      solve();
   return 0;
};

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值