2018-2019 ACM-ICPC, NEERC, Southern Subregional Contest, Qualification Stage

A. Coffee Break

排序之后优先队列搞一下就好了

//#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
const int MAXN = 2e5+7;
const int INF = 0x3f3f3f3f;
int n,m,d,pos[MAXN]; int main(){
____();
cin >> n >> m >> d;
vector<pair<int,int>> vec(n);
for(int i = 0; i < n; i++){
cin >> vec[i].first;
vec[i].second = i;
}
sort(vec.begin(),vec.end());
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> que;
int tot = 0;
que.push(make_pair(-INF,++tot));
for(auto &p : vec){
int id = p.second, w = p.first;
if(que.top().first+d>=w) que.push(make_pair(-INF,++tot));
auto pr = que.top();
que.pop();
pr.first = w;
pos[id] = pr.second;
que.push(pr);
}
cout << tot << endl;
for(int i = 0; i < n; i++) cout << pos[i] << ' '; cout << endl;
return 0;
}

B.Glider

如果到了一块区间,那么必然会走完这块区间

而且必然是从某一块区间的最左边开始的

所以枚举每一个区间,二分找到最右边的可以到达的区间,用前缀和维护一下

//#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
const int MAXN = 2e5+7;
int n,h,pref[MAXN];
pair<int,int> pr[MAXN];
void solve(){
cin >> n >> h;
for(int i = 1; i <= n; i++) cin >> pr[i].first >> pr[i].second;
for(int i = 2; i <= n; i++) pref[i] = pref[i-1] + pr[i].first - pr[i-1].second;
int ret = 0;
for(int i = 1; i <= n; i++){
int l = i, r = n;
while(l<=r){
int mid = (l+r) >> 1;
if(pref[mid] - pref[i] < h) l = mid + 1;
else r = mid - 1;
}
ret = max(ret,pr[r].second - pr[i].first + 1 + h - (pref[r] - pref[i]) - 1);
}
cout << ret << endl;
}
int main(){
____();
solve();
return 0;
}

C.Bacteria

除gcd之后判断是否是\(2\)的次方

然后全部加和不断加\(lowbit\)直到变成\(2^x\)即可

//#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
const int MAXN = 2e5+7;
typedef long long int LL;
#define lowbit(x) (x&-x)
LL n,A[MAXN];
int main(){
____();
cin >> n;
for(int i = 1; i <= n; i++) cin >> A[i];
LL g = 0; for(int i = 1; i <= n; i++) g = __gcd(g,A[i]);
for(int i = 1; i <= n; i++) A[i] /= g;
for(int i = 1; i <= n; i++) if(__builtin_popcount(A[i])!=1){
cout << -1 << endl;
return 0;
}
LL tot = accumulate(A+1,A+1+n,0ll);
int ret = 0;
while(tot!=lowbit(tot)) tot += lowbit(tot), ret++;
cout << ret << endl;
return 0;
}

D.Masquerade strikes back

对于每个数找出所有因子,然后组合一下

//#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
const int MAXN = 2e5+7;
int n;
pair<int,int> A[MAXN],ret[MAXN];
vector<int> prime;
bool npm[MAXN];
void sieve(){
for(int i = 2; i < MAXN; i++){
if(!npm[i]) prime.push_back(i);
for(int j = 0; j < (int)prime.size(); i++){
if(i*prime[j]>=MAXN) break;
npm[i*prime[j]] = true;
if(i%prime[j]==0) break;
}
}
}
vector<pair<int,int> > getfact(int x){
map<int,int> fct;
for(int i = 0; prime[i] * prime[i] <= x; i++){
int &p = prime[i];
while(x%p==0){
fct[p]++;
x /= p;
}
if(x==1) break;
}
if(x!=1) fct[x]++;
vector<pair<int,int> > vec;
for(auto &p : fct) vec.push_back(p);
return vec;
}
void dfs(int pos, vector<pair<int,int> > &vec, vector<int> &vc, int &cnt, int prod){
if(pos==(int)vec.size()){
vc.push_back(prod);
cnt--; return;
}
for(int i = 0; i <= vec[pos].second; i++){
if(i) prod *= vec[pos].first;
dfs(pos+1,vec,vc,cnt,prod);
if(!cnt) return;
}
}
int main(){
____();
sieve();
cin >> n;
for(int i = 1; i <= n; i++) cin >> A[i].first;
for(int i = 1; i <= n; i++) A[i].second = i;
sort(A+1,A+1+n);
for(int i = 1, r; i <= n; i = r + 1){
r = i;
while(r<n and A[r+1].first==A[i].first) r++;
int num = r - i + 1;
if(A[i].first==1){
if(num>1){
cout << "NO" << endl;
return 0;
}
else{
ret[A[i].second] = make_pair(1,1);
continue;
}
}
vector<pair<int,int> > vec = getfact(A[i].first);
int tot = 1;
for(auto &pr : vec) tot = tot * (pr.second + 1);
if(tot<num){
cout << "NO" << endl;
return 0;
}
vector<int> vc;
dfs(0,vec,vc,num,1);
for(int j = i; j <= r; j++) ret[A[j].second] = make_pair(vc[j-i],A[i].first/vc[j-i]);
}
cout << "YES" << endl;
for(int i = 1; i <= n; i++) cout <<ret[i].first << ' ' << ret[i].second << endl;
return 0;
}

E.Painting the Fence

线段树区间置值

重复出现的修改只需要改一次

//#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
const int MAXN = 3e5+7;
int n,m,A[MAXN],vis[MAXN];
vector<int> pos[MAXN];
struct SegmentTree{
int l[MAXN<<2],r[MAXN<<2],col[MAXN<<2];
#define ls(rt) rt << 1
#define rs(rt) rt << 1 | 1
void build(int L, int R, int rt = 1){
l[rt] = L, r[rt] = R;
if(L+1==R){
col[rt] = A[L];
return;
}
int mid = (L+R) >> 1;
build(L,mid,ls(rt)); build(mid,R,rs(rt));
}
void pushdown(int rt){
if(!col[rt]) return;
col[ls(rt)] = col[rs(rt)] = col[rt];
col[rt] = 0;
}
void update(int L, int R, int c, int rt = 1){
if(L>=r[rt] or l[rt]>=R) return;
if(L<=l[rt] and r[rt]<=R){
col[rt] = c;
return;
}
pushdown(rt);
update(L,R,c,ls(rt)); update(L,R,c,rs(rt));
}
int query(int pos, int rt = 1){
if(l[rt] + 1 == r[rt]) return col[rt];
pushdown(rt);
int mid = (l[rt] + r[rt]) >> 1;
if(pos<mid) return query(pos,ls(rt));
else return query(pos,rs(rt));
}
}ST;
int main(){
scanf("%d",&n);
for(int i = 1; i <= n; i++){
scanf("%d",&A[i]);
pos[A[i]].push_back(i);
}
scanf("%d",&m);
ST.build(1,MAXN);
for(int i = 1; i <= m; i++){
int op; scanf("%d",&op);
if(vis[op]) continue;
vis[op] = true;
int lmax = 0x3f3f3f3f, rmax = 0;
for(auto p : pos[op]) if(ST.query(p)==op) lmax = min(lmax,p), rmax = max(rmax,p);
if(lmax>=rmax) continue;
ST.update(lmax,rmax+1,op);
}
for(int i = 1; i <= n; i++) printf("%d ",ST.query(i));
puts("");
return 0;
}

F.Tickets

前缀和

//#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
const int MAXN = 1e6+7;
const int D = 30;
int n,pre[MAXN][D]; int calc(int x){
int l = x / 1000;
int r = x % 1000;
int ret = 0;
while(l) ret += l % 10, l /= 10;
while(r) ret -= r % 10, r /= 10;
return abs(ret);
}
void preprocess(){
pre[0][0] = 1;
for(int i = 1; i < 1000000; i++){
int x = calc(i);
for(int j = 0; j < D; j++) pre[i][j] = pre[i-1][j];
pre[i][x]++;
}
}
void solve(){
int x; cin >> x;
int ret = 0, v = calc(x);
for(int i = 0; i < v; i++) ret += pre[x][i];
cout << ret << endl;
}
int main(){
____();
preprocess();
for(cin >> n; n; n--) solve();
return 0;
}

G.Tree Reconstruction

拉成一条链即可

//#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
const int MAXN = 1111;
set<int> S;
int n;
pair<pair<int,int>,int> pr[MAXN];
pair<int,int> ret[MAXN];
int main(){
____();
cin >> n;
for(int i = 1; i < n; i++) cin >> pr[i].first.first >> pr[i].first.second;
for(int i = 1; i < n; i++) if(pr[i].first.first>pr[i].first.second) swap(pr[i].first.first,pr[i].first.second);
for(int i = 1; i < n; i++){
if(pr[i].first.second!=n){
cout << "NO" << endl;
return 0;
}
pr[i].second = i;
}
sort(pr+1,pr+n);
for(int i = 1; i <= n; i++) S.insert(i);
int maxx = 0;
vector<int> vec;
for(int i = 1; i < n; i++){
if(pr[i].first.first>maxx){
vec.push_back(pr[i].first.first);
S.erase(pr[i].first.first);
maxx = pr[i].first.first;
}
else{
int u = *S.begin();
S.erase(S.begin());
if(u>pr[i].first.first){
cout << "NO" << endl;
return 0;
}
vec.push_back(u);
}
}
vec.push_back(n);
cout << "YES" << endl;
for(int i = 1; i < n; i++) ret[pr[i].second] = make_pair(vec[i-1],vec[i]);
for(int i = 1; i < n; i++) cout << ret[i].first << ' ' << ret[i].second << endl;
return 0;
}

H.Theater Square

简单计算一下

//#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
int n,m,x1,y1,x2,y2;
int main(){
____();
cin >> n >> m >> x1 >> y1 >> x2 >> y2;
cout << ((x1 - 1 + n - x2) * (m%2) + (x2-x1+1) * ((y1-1)%2 + (m-y2)%2) + 1) / 2 << endl;
return 0;
}

I.Heist

签到

//#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
int n,A[1111];
int main(){
____();
cin >> n;
for(int i = 1; i <= n; i++) cin >> A[i];
cout << *max_element(A+1,A+1+n) - *min_element(A+1,A+1+n) + 1 - n << endl;
return 0;
}

J.Buying a TV Set

除gcd之后取长宽最小倍数

//#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
typedef long long int LL;
LL a,b,x,y;
int main(){
____();
cin >> a >> b >> x >> y;
LL d = __gcd(x,y);
x /= d; y /= d;
cout << min(a/x,b/y) << endl;
return 0;
}

K.Medians and Partition

大于等于\(m\)的变成\(1\)

小于\(m\)的变成\(-1\)

然后贪心分段,保证分段之后前后依然是\(m\ good\)的

//#pragma GCC optimize("O3")
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
function<void(void)> ____ = [](){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);};
const int MAXN = 5e3+7;
int n,m,A[MAXN],pref[MAXN];
int main(){
____();
cin >> n >> m;
for(int i = 1; i <= n; i++) cin >> A[i];
for(int i = 1; i <= n; i++){
if(A[i]>=m) A[i] = 1;
else A[i] = -1;
}
for(int i = 1; i <= n; i++) pref[i] = pref[i-1] + A[i];
if(pref[n]<=0){
cout << 0 << endl;
return 0;
}
int last = 0, num = 1;
for(int i = 1; i <= n; i++){
if(pref[i]-pref[last]>0 and pref[n] - pref[i]>0){
num++;
last = i;
}
}
cout << num << endl;
return 0;
}

L.Ray in the tube

2018-2019 ACM-ICPC, NEERC, Southern Subregional Contest, Qualification Stage(11/12)的更多相关文章

  1. 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage

    2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage A. Union of Doubly Link ...

  2. 2019.04.18 第六次训练 【2018-2019 ACM-ICPC, NEERC, Southern Subregional Contest, Qualification Stage】

    题目链接: https://codeforces.com/gym/101911 又补了set的一个知识点,erase(it)之后it这个地址就不存在了,再引用的话就会RE A: ✅ B:  ✅ C: ...

  3. D. Dog Show 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred)

    http://codeforces.com/contest/847/problem/D 巧妙的贪心 仔细琢磨... 像凸包里的处理 #include <cstdio> #include & ...

  4. 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred)

    题目链接:http://codeforces.com/problemset/problem/847/I I. Noise Level time limit per test 5 seconds mem ...

  5. 2018-2019 ICPC, NEERC, Southern Subregional Contest

    目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...

  6. Codeforces 2018-2019 ICPC, NEERC, Southern Subregional Contest

    2018-2019 ICPC, NEERC, Southern Subregional Contest 闲谈: 被操哥和男神带飞的一场ACM,第一把做了这么多题,荣幸成为7题队,虽然比赛的时候频频出锅 ...

  7. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror) Solution

    从这里开始 题目列表 瞎扯 Problem A Find a Number Problem B Berkomnadzor Problem C Cloud Computing Problem D Gar ...

  8. 2018.10.20 2018-2019 ICPC,NEERC,Southern Subregional Contest(Online Mirror, ACM-ICPC Rules)

    i207M的“怕不是一个小时就要弃疗的flag”并没有生效,这次居然写到了最后,好评=.= 然而可能是退役前和i207M的最后一场比赛了TAT 不过打得真的好爽啊QAQ 最终结果: 看见那几个罚时没, ...

  9. Codeforces1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)总结

    第一次打ACM比赛,和yyf两个人一起搞事情 感觉被两个学长队暴打的好惨啊 然后我一直做傻子题,yyf一直在切神仙题 然后放一波题解(部分) A. Find a Number LINK 题目大意 给你 ...

随机推荐

  1. Linux服务器下安装Composer 并使用Composer安装Thinkphp5.0

    Composer官方文档:https://docs.phpcomposer.com/00-intro.htmlComposer是一个php的包管理器.要求php版本在5.3以上. 一.安装Compos ...

  2. LeetCode344 反转字符串

    编写一个函数,其作用是将输入的字符串反转过来. 示例 1: 输入: "hello" 输出: "olleh" 示例 2: 输入: "A man, a p ...

  3. 【C++】《C++ Primer 》第十四章

    第十四章 重载运算与类型转换 一.基本概念 重载运算符是具有特殊名字的函数:由关键字operator和其后要定义的运算符号共同组成.也包含返回类型.参数列表以及函数体. 当一个重载的运算符是成员函数时 ...

  4. 2020周阳SpringCloud完整版笔记--一

    微服务架构入门 微服务 的概念最早产生于Martin Fowler在2014年的一篇论文中. 微服务架构是一种架构模式,他提倡将单一应用程序划分成一组小的服务,服务与服务之间互相协调.相互配合,为用户 ...

  5. [工作札记]02: .Net Winform控件TreeView最简递归绑定方法

    前言:Treeview控件是我们在WinForm.WebForm开发中经常使用的控件,需要从数据库动态加载数据,然后递归绑定每一个节点:同样,递归的思路在其他程序中也经常运用,包括.Net MVC等. ...

  6. rm: cannot remove `/tmp/localhost-mysql_cacti_stats.txt': Operation not permitted

    [root@DBslave tmp]# chown zabbix.zabbix /tmp/localhost-mysql_cacti_stats.txt

  7. 【Oracle】等待事件之 V$SESSION_WAIT

    (1)-V$SESSION_WAIT 这是一个寻找性能瓶颈的关键视图.它提供了任何情况下session在数据库中当前正在等待什么(如果session当前什么也没在做,则显示它最后的等待事件).当系统存 ...

  8. Python设计模式面向对象编程

    前言   本篇文章是基于极客时间王争的<设计模式之美>做的总结和自己的理解.  说到面向对象编程,作为一个合格的Pythoner,可以说信手拈来.毕竟在Python里"万物都是对 ...

  9. Py层次递进与文件修改大程序,模块,name与file

    层次的递进与返回 #输入quit的时候返回上一阶层,输入exit退出所有的循环 tag=True while tag==True: level1=input('level1:') if level1= ...

  10. SQL Server 日志收缩方法

    在日常运维中,有时会遇到"The transaction log for database 'xxxx' is full due to 'ACTIVE_TRANSACTION'." ...