Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- struct elem {
- int key,value;
- struct elem * next;
- };
- int modl(int x) {
- return x>0 ? x : -1*x;
- }
- struct elem * Initelem() {
- struct elem * a = (struct elem *)malloc(sizeof(struct elem));
- a->next = NULL;
- a->key = 0;
- a->value = 0;
- return a;
- }
- struct elem ** Inittable(int size) {
- struct elem ** a = (struct elem**)malloc(size*sizeof(struct elem*));
- for(int i = 0;i<size;i++) a[i] = Initelem();
- return a;
- }
- void Insertelem(int value,int key,struct elem ** table,int size) {
- struct elem * a = Initelem();
- a->key = key;
- a->value = value;
- a->next = table[modl(key % size)];
- table[modl(key % size)] = a;
- }
- int Searchelem(struct elem ** table,int size,int key) {
- struct elem * a = table[modl(key % size)];
- while((a != NULL) && (a->key != key)) a = a->next;
- return a;
- }
- int freeallsum(struct elem ** table,int size) {
- int sum = 0;
- for(int i = 0;i<size;i++) {
- struct elem * a = table[i];
- struct elem *b;
- while(a != NULL) {
- sum += (a->value + 1) * a->value / 2;
- b = a->next;
- free(a);
- a = b;
- }
- }
- free(table);
- return sum;
- }
- int main()
- {
- int size,x,key = 0;
- scanf("%d" , &size);
- struct elem ** table = Inittable(size);
- for(int i = 0;i < size;i++) {
- scanf("%d" , &x);
- key ^= x;
- struct elem * a = Searchelem(table,size,key);
- if (a) ++a->value;
- else if (key == 0)
- Insertelem(1,key,table,size);
- else Insertelem(0,key,table,size);
- }
- printf("%d" , freeallsum(table,size));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement