Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**********************************************************************************/
- /* Problem: z033 "吃點心" from 2017 NPSC 國中組初試 */
- /* Language: C++ */
- /* Result: AC (1690ms, 26197KB) on ZeroJudge */
- /* Author: sifmelcara at 2019-04-21 10:43:15 */
- /**********************************************************************************/
- #include <cstdio>
- #include <iostream>
- #include <cstdlib>
- #include <cstring>
- #include <map>
- using namespace std ;
- // https://www.boost.org/doc/libs/1_64_0/boost/functional/hash/hash.hpp
- template <typename SizeT>
- inline void hash_combine_impl(SizeT& seed, SizeT value)
- {
- seed ^= value + 0x9e3779b9 + (seed<<6) + (seed>>2);
- }
- uint64_t hashPair(uint64_t v1, uint64_t v2) {
- hash_combine_impl(v1, v2);
- return v1;
- }
- #define VAL_SIZE ((1<<21)+11)
- uint64_t val[VAL_SIZE];
- void build(int now, int l, int r) {
- if (l+1 == r) return;
- int mid = (l+r)/2;
- build(now*2, l, mid);
- build(now*2+1, mid, r);
- val[now] = hashPair(val[now*2], val[now*2+1]);
- }
- void toggle(int now, int l, int r, int loc) {
- if (loc < l) return;
- if (loc >= r) return;
- if (loc == l && l+1 == r) {
- val[now] ^= 0x123456789ULL;
- return;
- }
- int mid = (l+r)/2;
- toggle(now*2, l, mid, loc);
- toggle(now*2+1, mid, r, loc);
- val[now] = hashPair(val[now*2], val[now*2+1]);
- }
- int main()
- {
- for (int i = 0 ; i != VAL_SIZE ; i++)
- val[i] = rand() + (rand() << 30);
- int N;
- build(1, 0, 1<<20);
- while (~scanf("%d", &N)) {
- long long ans = 0;
- map<uint64_t, int> stat;
- stat[val[1]]++;
- for (int i = 0 ; i != N ; i++) {
- int a;
- scanf("%d", &a);
- toggle(1, 0, 1<<20, a);
- ans += stat[val[1]];
- stat[val[1]]++;
- }
- cout << ans << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement