Toy(toy,cpp/toy.in/toy.out):
4
0 7
1 5
1 3
2 6
7 3 6 5
分析:两种解法
Guinness(guinness.cpp/guinness.in/guinness.out):
4
2 11 12 15
2
4
1 3 10 14
3
5 6 18
1 2 2 4
4 4 9
分析:三种正解
$Code$:
for
覆盖会超时,用600个数组会超空间,所以滚动数组就可以在这里。#include <iostream>
#include <cstdio>
#define INF 2147483647
using namespace std;
const int MAXN=2e5+5;
int m,n,data[4][MAXN],len[4],a,b,c;
inline int in(){
int X=0,w=0; char ch=0;
while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
return w?-X:X;
}
inline void out(int x){
if(x<0) putchar('-'),x=-x;
if(x>9) out(x/10);
putchar(x%10+'0');
}
inline int Mod(int num,int x){
return (num&(x-1));
}
inline void update(){
a=Mod(a+1,4);
b=Mod(b+1,4);
c=Mod(c+1,4);
return;
}
int main(){
m=in();
a=1;
b=0;
c=2;
len[a]=m;
for (register int i=1;i<=m;i++){
data[a][i]=in();
}
n=in();
while (n--){
len[b]=in();
for (register int l=1;l<=len[b];l++){
data[b][l]=in();
}
int i=1,j=1,k=0;
data[a][len[a]+1]=INF;
data[b][len[b]+1]=INF;
while (i<=len[a]||j<=len[b]){
if (data[a][i]<data[b][j]){
data[c][++k]=data[a][i++];
}
else {
data[c][++k]=data[b][j++];
out(i);
printf (" ");
}
}
len[c]=k;
printf ("\n");
update();
}
return 0;
}
2. 树状数组:老师的标程
#include <bits/stdc++.h>
using namespace std;
#define initIO(pn) freopen(pn ".in", "r", stdin), freopen(pn ".out", "w", stdout)
const int MAXM = 1e6 + 10;
const int MAXN = 610;
int B[MAXM];
vector<int> r, v[MAXN];
map<int, int> mp;
int lowbit(int x) {
return x & (-x);
}
void update(int x, int v) {
for (; x < MAXM; x += lowbit(x))
B[x] += v;
}
int query(int x) {
int res = 0;
for (; x; x -= lowbit(x))
res += B[x];
return res;
}
int main() {
int n, m, x;
initIO("guinness");
cin >> m;
for (int i = 1; i <= m; i++) {
cin >> x;
v[0].push_back(x);
r.push_back(x);
}
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> m;
for (int j = 1; j <= m; j++) {
cin >> x;
v[i].push_back(x);
r.push_back(x);
}
}
sort(r.begin(), r.end());
for (int i = 0; i < r.size(); i++)
mp[r[i]] = i + 1;
for (int i = 0; i <= n; i++)
for (int j = 0; j < v[i].size(); j++)
v[i][j] = mp[v[i][j]];
for (int i = 0; i < v[0].size(); i++)
update(v[0][i], 1);
for (int i = 1; i <= n; i++) {
for (int j = 0; j < v[i].size(); j++)
cout << query(v[i][j]) + 1 << " ";
cout << endl;
for (int j = 0; j < v[i].size(); j++)
update(v[i][j], 1);
}
return 0;
}
Furit(furit.cpp/furit.in/furit.out):
7
2 2 3
2 4 5
2 6 7
0
0
0
0
3
基础
$STL$
vector
stack
queue
set
map
priority_queue
string
算法:
数据结构:
普及
搜索:
$DP$动态规划:
图论:
数据结构:
提高
搜索:
数据结构:
图论:
网络流
字符串:
本文作者:Snowflake_Pink
本文链接:https://snowflake.pink/archives/31/
最后修改时间:2020-04-13 11:17:13
本站未注明转载的文章均为原创,并采用 CC BY-NC-SA 4.0 授权协议,转载请注明来源,谢谢!