码迷,mamicode.com
首页 > 其他好文 > 详细

2019银川现场赛补题

时间:2020-04-25 10:27:59      阅读:48      评论:0      收藏:0      [点我收藏+]

标签:--   hang   algorithm   print   make   amp   def   space   size   

I. Base62

x,y,z = (input().split())
x = int(x)
y = int(y)
num = []
map = {}
for i in range(62):
    if i < 10:
        num.append(chr(i+48))
    elif i < 36:
        num.append(chr(i-10+65))
    else:
        num.append(chr(i-36+97))
    map[num[i]] = i
cnt = 0
ans = []
for i in z:
    t = map[i]
    cnt = cnt * x + t

while cnt > 0:
    ans.append(num[cnt % y])
    cnt = cnt // y
if len(ans) == 0:
    ans.append(0)
ans.reverse()
for i in ans:
    print(i,end = "")

G. Pot!!

#include <cstdio>
#include <iostream>
#include <queue>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;
#define ll long long
#define P pair<int,int>
#define mk make_pair
const ll INF=1e18;
const int N=1e5+10;
ll a[N];
struct SegmentTree{
    int l,r;
    ll maxn;
    ll dat;
}t[N*4][4];
void build(int p,int l,int r,int i)
{
    t[p][i].l = l;
    t[p][i].r = r;
    t[p][i].dat = 0;
    if(t[p][i].l == t[p][i].r){t[p][i].maxn = 0;return ;}
    int mid = (l+r)/2;
    build(p*2,l,mid,i);
    build(p*2+1,mid+1,r,i);
    t[p][i].maxn = max(t[p*2][i].maxn,t[p*2+1][i].maxn);
}
void spread(int p,int i)
{
    if(t[p][i].dat)
    {
        t[p*2][i].maxn += t[p][i].dat;
        t[p*2+1][i].maxn += t[p][i].dat;
        t[p*2][i].dat += t[p][i].dat;
        t[p*2+1][i].dat += t[p][i].dat;
        t[p][i].dat = 0;
    }
}
void change(int p,int l,int r,ll v,int i)
{
    if(l <= t[p][i].l && t[p][i].r <= r)
    {
        t[p][i].dat += v;
        t[p][i].maxn += v;
        return ;
    }
    int mid = (t[p][i].l+t[p][i].r)/2;
    spread(p,i);
    if(l<=mid) change(p*2,l,r,v,i);
    if(r>mid) change(p*2+1,l,r,v,i);
    t[p][i].maxn = max(t[p*2][i].maxn,t[p*2+1][i].maxn);
}
ll ask(int p,int l,int r,int i)
{
    if(l<=t[p][i].l&&r>=t[p][i].r)
        return t[p][i].maxn;
    int mid = (t[p][i].l+t[p][i].r)/2;
    spread(p,i);
    ll maxn = 0;
    if(l<=mid) maxn = max(maxn,ask(p*2,l,r,i));
    if(r>mid) maxn = max(maxn,ask(p*2+1,l,r,i));
    return maxn;
}
vector<P>num[11];
void init()
{
    int map[10];
    map[2] = 0,map[3] = 1,map[5] = 2,map[7] = 3;
    for(int i=2;i<=10;i++){
        int x = i;
        for(int j=2;j<=x;j++){
            int sum = 0;
            while(x%j==0){
                sum++;
                x = x / j;
            }
            if(sum){
                num[i].push_back(mk(map[j],sum));
            }
        }
    }
}
int main()
{
    ios::sync_with_stdio(false);
    init();
    int n,q;
    cin >> n >> q;
    for(int i=0;i<4;i++){
        build(1,1,n,i);
    }
    while(q--){
        string s;
        cin >> s;
        if(s[1]==‘U‘){
            int l,r,x;
            cin >> l >> r >> x;
            for(int i=0;i<num[x].size();i++){
                change(1,l,r,num[x][i].second,num[x][i].first);
            }
        }
        else{
            int l,r;
            cin >> l >> r;
            int ans = 0;
            for(int i=0;i<4;i++){
                ans = max(ans*1LL,ask(1,l,r,i));
            }
            printf("ANSWER %d\n",ans);
        }
    }
    return 0;
}

2019银川现场赛补题

标签:--   hang   algorithm   print   make   amp   def   space   size   

原文地址:https://www.cnblogs.com/hh13579/p/12771705.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!