当前位置: 首页 > news >正文

中国化学工程第九建设公司网站淘宝的关键词排名怎么查

中国化学工程第九建设公司网站,淘宝的关键词排名怎么查,电子商务门户网站的研究与实现,wordpress如何直接设置下载Codeforces Round 853 (Div. 2) C. Serval and Toxels Arrays 思路: 求任意两个组合的元素个数。 注意到,其实每个元素都是独立的。他在任意组合的出现情况组成的贡献是可以分开讨论的。我们讨论元素x。假设x在m1个数组中出现了cnt次(一个…

Codeforces Round 853 (Div. 2)

C. Serval and Toxel's Arrays

思路:

求任意两个组合的元素个数。

  1. 注意到,其实每个元素都是独立的。他在任意组合的出现情况组成的贡献是可以分开讨论的。
  2. 我们讨论元素x。假设x在m+1个数组中出现了cnt次(一个数组最多只有一个x)。
  3. 那么对于任意两个数组可能出现的情况有:
    1. 同时有x,这样的组合是C(2,cnt),贡献1
    2. 只有一个有x,这样的组合是cnt*(m+1-cnt),贡献1
    3. 都没有x,不用讨论,贡献0
  4. 我们把每个数都分别这样讨论,就是答案。
#include <bits/stdc++.h>
using namespace std;
#define ll     long long
typedef unsigned long long ull;
typedef pair<long long, long long> pll;
typedef pair<int, int> pii;//double 型memset最大127,最小128
//std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
const int INF = 0x3f3f3f3f;         //int型的INF
const ll llINF = 0x3f3f3f3f3f3f3f3f;//ll型的llINF
const int N = 4e5 + 10;int a[N];
int cnt[N];
int main()
{std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);int t;cin >> t;while (t--){int n, m;cin >> n >> m;for (int i = 0; i <= n + m; ++i)cnt[i] = 0;for (int i = 1; i <= n; ++i){cin >> a[i];cnt[a[i]] = m + 1; //如果一个数没被修改,他会一直出现,共m+1次}int p, v;for (int i = 1; i <= m; ++i){cin >> p >> v;cnt[a[p]] -= m - i + 1; //被修改的数后面都不会再出现了(除非再给一次)cnt[v] += m - i + 1; //新的数后面都会出现(直到被修改没)a[p] = v;}ll ans = 0;for (int i = 1; i <= n + m; ++i)ans += (ll)cnt[i] * (cnt[i] - 1) / 2 + (ll)cnt[i] * (m + 1 - cnt[i]);cout << ans << endl;}return 0;
}

D. Serval and Shift-Shift-Shift

思路:

  1. 看数据,1e3,说明我们可以进行复杂度为O(N^2)的操作
  2. 首先,只要a至少存在一个1,我可以用1产生任何值(按位一位一位操作,可以把他们变成想要的1或者0),除了0(因为要求位移至少为1,所以不能消去自己)
  3. 当我们a的最高位1右区间需要1或者0时,我们可以把最高位移动到那里修改他,这个操作遍历右区间,我们每次操作,因为最高位1左边都是0,所以不会对操作位左边产生影响。而操作位右边有影响没事,我会一位一位向右过去修改。
  4. 修改左区间同理,找最小位1,不断左移修改左区间(不能还是从高位修改到低位),我们这次是利用不影响右区间,左区间等下会修改。两者相反。
  5. 最后,注意到a,b要么同时为0,要么同时不为0(a为0,无法变成非0,a不为0,无法变成0)
#include <bits/stdc++.h>
using namespace std;
#define ll     long long
typedef unsigned long long ull;
typedef pair<long long, long long> pll;
typedef pair<int, int> pii;//double 型memset最大127,最小128
//std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
const int INF = 0x3f3f3f3f;         //int型的INF
const ll llINF = 0x3f3f3f3f3f3f3f3f;//ll型的llINF
const int N = 2e3 + 10;bool a[N], b[N], c[N];
int ans[N];void mysolve()
{int n;string a1, b1;cin >> n >> a1 >> b1;if (a1 == b1){cout << 0 << endl;return;}int cnta = 0, cntb = 0; //记录啊a与b1的个数int cnt = 0; //操作数for (int i = 0; i < n; ++i){a[i] = a1[i] - '0', b[i] = b1[i] - '0';if (a[i])cnta++;if (b[i])cntb++;}//同时非0if (cnta && cntb){int ha = n, hb = n; //记录a与b的最高位1for (int i = 0; i < n; ++i)if (a[i]){ha = i;break;}for (int i = 0; i < n; ++i)if (b[i]){hb = i;break;}//修改b最高位1及往右的区间for (int i = hb; i < n; ++i){if (a[i] != b[i]){int tmp = i - ha; //表示位移ans[++cnt] = ha - i;//先记录,后面ha可能更新memcpy(c, a, sizeof(a)); //不能直接a数组间去异或,途中会修改a的for (int j = i; j < n; ++j){if (j - tmp >= n)break; //越界后面都是异或0了a[j] ^= c[j - tmp];if (a[j])ha = min(ha, j); //hb大于ha时,可能更新ha}}}if (ha < hb) //如果ha小于(注意,越高位越小,不是大于),那么需要把hb前面的1去掉{int la = 0; //a的最低位1for (int i = n - 1; i >= 0; --i)if (a[i]){la = i;break;}for (int i = hb - 1; i >= 0; --i) //往左更新{if (a[i]) //是1就删{int tmp = i - la;ans[++cnt] = la - i;memcpy(c, a, sizeof(a));for (int j = i; j >= 0; --j){if (j - tmp < 0)break;a[j] ^= c[j - tmp];}}}}cout << cnt << endl;for (int i = 1; i <= cnt; ++i)cout << ans[i] << ' ';cout << endl;}else cout << -1 << endl;
}int main()
{std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);int t;cin >> t;while (t--){mysolve();}return 0;
}

http://www.dt0577.cn/news/11210.html

相关文章:

  • 做外贸是网站好还是展会好怎么优化网站性能
  • 韵达快递小网站怎么做seo收录查询
  • flash 网站带后台揭阳百度快照优化排名
  • 做网站靠广告一年赚多少钱网站秒收录工具
  • wordpress建站需要多久域名站长工具
  • 联想网络营销推广方法网站优化方案设计
  • 网站做三个月收录100营销推广是什么意思
  • 松原市网站建设可以推广发广告的app
  • 免费信息网站排名竞价排名是什么意思
  • 长沙市网站开发营销策划方案怎么写
  • 找网站做企业网站建设目标
  • 商场网站开发教程b2b电子商务网
  • 网站备案密码能改吗嵌入式培训班一般多少钱
  • 域名买好后怎么建设网站常见搜索引擎有哪些
  • 网站首页专题怎么做今日十大热点新闻头条
  • 制作网站背景怎么做seo结算系统
  • 做网站实时数据用接口百度推广开户费用
  • 雁塔区网站建设百度推广客户端电脑版
  • phpcms 网站名称标签深圳 网站制作
  • 为什么要给企业建设网站seo咨询解决方案
  • 品牌网站官网dw软件怎么制作网页
  • 顺德网络营销网站长沙网站seo收费
  • 网站建设款分录数据分析师
  • dedecms做论坛网站sem是指什么
  • 创意礼品做的比较好的网站关键词林俊杰mp3
  • 福建住房和城乡建设网站seo发外链的网站
  • 韩国网站模板磁力宅
  • 做网站需要哪些人员舆情通
  • 360免费建站模板seo网站关键词优化报价
  • 武清网站建设公关