2021杭电多校5

过题:4
排名:165
这场不仅题意不明,而且范围改来改去,甚至出题人还把样例算错了,锅比较多。(样例更正之前过的那些人究竟是怎么过的。。。。)

1006 ( Cute Tree )

CY
记忆化搜索

#include <bits/stdc++.h>
typedef long long ll;
const int MAXN = 2e5 + 10;
int a[MAXN];
std::map < int, ll > mp;
ll dfs(int n)
{
    if (mp.find(n) != mp.end()) return mp[n];
    if (n == 1) return mp[n] = 1;
    else if (n == 2) return mp[n] = 3;
    else
    {
        int x = n / 3 + (n % 3 != 0);
        return mp[n] = dfs(x) + dfs(n - x >> 1) + dfs(n - x - (n - x >> 1)) + 1;
    }
}
int main()
{
    int t; scanf("%d", &t);
    while (t--)
    {
        int n; scanf("%d", &n);
        for (int i = 1; i <= n; ++i)
            scanf("%d", &a[i]);
        mp.clear();
        printf("%lld\n", dfs(n));
    }
    return 0;
}

1003 ( VC Is All You Need )

WYX+CY+WXL

#include <bits/stdc++.h>
typedef long long ll;
int main()
{
    int t; scanf("%d", &t);
    while (t--)
    {
        ll n, k; scanf("%lld%lld", &n, &k);
        if (k + 1 >= n) printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}

1007 ( Banzhuan )

就是这题,出题人把样例自己算错了。。。
WYX+CY

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e4+10;
const int inf=0x3f3f3f3f;
const int p=1e9+7;
ll qpow(ll a,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1) ans=ans*a%p;
        n>>=1;
        a=a*a%p;
    }
    return ans;
}
int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);  
    // for(int i=1;i<=10;i++)
    // {
    //     ll ans=0;
    //     for(int j=1;j<=i;j++)
    //     ans+=j*(i-j+1)*(i-j+1);
    //     cout<<ans<<" ";
    // }
    int t;cin>>t;
    while(t--)
    {
        ll n;cin>>n;n%=p;
        if(n==1) {
            cout<<1<<endl<<1<<endl;
            continue;
        }
        ll ans=0;
        ans=n*(n+1)%p*qpow(12,p-2)%p*n%p*(n+1)%p*(2*n+1)%p;
        // cout<<ans<<endl;
       // ll ans1=(n-1)*(n+2)%p*qpow(8,p-2)%p*n%p*n%p*(n+1)%p*(n+1)%p;
        ll ans1=(n-1)*(n+2)%p*qpow(24,p-2)%p*(n+1)%p*(n+1)%p*((((n+1)*(n+1)%p-1)%p+p)%p)%p;
        ll ans2=(n-1)*(n+2)%p*qpow(12,p-2)%p*(((n*(n+1)%p*(2*n+1)%p+3*n*(n+1)%p-12)%p+p)%p)%p;
        ans2=((ans2+ans)%p+p)%p;
        ans=((ans+ans1)%p+p)%p;
        
        cout<<ans2<<endl;
        ans=n*n%p*n%p*(n+1)%p*qpow(12,p-2)%p*n%p*(n+1)%p*(2*n+1)%p;
        cout<<(ans+p)%p<<endl;
    }
     return 0;
}

1009 ( Array )

*** WXL***
用线段树会TLE,需要用树状数组。
复杂度 O ( n l o g n ) O(nlogn) O(nlogn),本来这个复杂度是过不去的,必须线性,后来出题人修改了数据范围从而可过

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
const int N = 2e6+6;
// 修改差分 来维护前缀和的前缀和
// c1 为差分d c2为d*i  c3 为d*i*i
LL c1[N * 2], c2[N * 2], c3[N * 2];
LL sum(int x)
{
   LL res = 0;
   for (int i = x; i > 0; i -= i & -i)
   {
      res += c1[i] * (x + 2) * (x + 1) - c2[i] * (2 * x + 3) + c3[i];
   }
   return res / 2;
}
void add(int x, LL d, int n)
{
   for (int i = x; i <= n; i += i & -i)
   {
      c1[i] += d;
      c2[i] += d * x;
      c3[i] += d * x * x;
   }
}
int a[N];
vector<int> b[N];
int bb[N];
int main()
{
   int T;
   scanf("%d", &T);
   while (T--)
   {
      int n;
      scanf("%d", &n);
      for (int i = 1; i <= n; i++)
      {
         scanf("%d", &a[i]);
         b[i-1].clear();
         bb[i] = a[i];
      }
      sort(bb + 1, bb + 1 + n);
      int cnt = unique(bb + 1, bb + 1 + n) - bb - 1;
      for (int i = 1; i <= n; i++)
      {
         int c = lower_bound(bb + 1, bb + 1 + cnt, a[i]) - bb - 1;
         // cout << c << endl;
         b[c].push_back(i);
      }
      int wc = n + 1; // 偏移量,把[-n,n] 平移到 [1,2n+1]
      LL ans = 0;
      for(int i=0;i<=2*n+1;++i) c1[i] = 0;
      for(int i=0;i<=2*n+1;++i) c2[i] = 0;
      for(int i=0;i<=2*n+1;++i) c3[i] = 0;
      for (int i = 0; i < n; i++)
      {
         b[i].push_back(n + 1);
         int last = 0;
         for (int j = 0; j < b[i].size(); j++)
         {
            int y = 2 * j - last + wc, x = 2 * j - (b[i][j] - 1) + wc;
            // 查询 sum([1,t-1] 的权值和), 其中t在[x,y]范围内,
            ans += sum(y - 1) - (x >= 3 ? sum(x - 2) : 0);
            // [x,y] 这些数的权值+1
            // cout << "x: " << x << " y: " << y << endl;
            add(x, 1, 2 * n + 1);
            add(y + 1, -1, 2 * n + 1);
            last = b[i][j];
         }
         last = 0;
         for (int j = 0; j < b[i].size(); j++)
         {
            int y = 2 * j - last + wc, x = 2 * j - (b[i][j] - 1) + wc;
            add(x, -1, 2 * n + 1);
            add(y + 1, 1, 2 * n + 1);
            last = b[i][j];
         }
      }
      printf("%lld\n", ans);
      // return 0;
   }
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值