add priority queue

This commit is contained in:
Henry He
2024-02-29 23:42:09 +08:00
parent f2542611b0
commit 1166e99c92
25 changed files with 3613 additions and 3 deletions

View File

@ -0,0 +1,603 @@
Test Start
Normal test...
982602241 100 0
996868965 200 0
996868965 300 0
998445800 400 0
999728643 500 0
999728643 600 0
999728643 700 0
999728643 800 0
999728643 900 0
999728643 1000 0
999728643 1100 0
999728643 1200 0
999728643 1300 0
999728643 1400 0
999728643 1500 0
999728643 1600 0
999728643 1700 0
999728643 1800 0
999728643 1900 0
999728643 2000 0
992274188 100 0
992274188 200 0
992274188 300 0
992274188 400 0
992274188 500 0
992506721 600 0
992506721 700 0
992506721 800 0
992506721 900 0
992506721 1000 0
992506721 1100 0
997689697 1200 0
997689697 1300 0
997689697 1400 0
997689697 1500 0
997689697 1600 0
997689697 1700 0
997689697 1800 0
999057935 1900 0
999248333 2000 0
995816968 100 0
997592826 200 0
997592826 300 0
997592826 400 0
997592826 500 0
999526610 600 0
999526610 700 0
999526610 800 0
999526610 900 0
999526610 1000 0
999526610 1100 0
999526610 1200 0
999526610 1300 0
999526610 1400 0
999526610 1500 0
999526610 1600 0
999526610 1700 0
999526610 1800 0
999526610 1900 0
999526610 2000 0
Normal copy&= test...999978170 2100 0
999695902 2099 0
999125452 2098 0
998647558 2097 0
998318778 2096 0
998294892 2095 0
997257845 2094 0
996968740 2093 0
996955629 2092 0
995414877 2091 0
999194025 2190 0
998505026 2189 0
994764380 2188 0
993821835 2187 0
993564892 2186 0
993411094 2185 0
993337990 2184 0
989971433 2183 0
989695853 2182 0
989109013 2181 0
999978170 2100 0
999695902 2099 0
999125452 2098 0
998647558 2097 0
998318778 2096 0
998294892 2095 0
997257845 2094 0
996955629 2093 0
995414877 2092 0
994481585 2091 0
993821835 2190 0
993564892 2189 0
993337990 2188 0
990836789 2187 0
989695853 2186 0
989109013 2185 0
988821962 2184 0
988516017 2183 0
987536948 2182 0
987163675 2181 0
999978170 2100 0
999695902 2099 0
999125452 2098 0
998647558 2097 0
998318778 2096 0
998294892 2095 0
997257845 2094 0
997046486 2093 0
996955629 2092 0
995414877 2091 0
998430519 2190 0
993821835 2189 0
993564892 2188 0
993337990 2187 0
990078347 2186 0
989695853 2185 0
989109013 2184 0
988821962 2183 0
988516017 2182 0
987536948 2181 0
999978170 2100 0
999695902 2099 0
999125452 2098 0
998647558 2097 0
998318778 2096 0
998294892 2095 0
997257845 2094 0
996955629 2093 0
995414877 2092 0
993821835 2091 0
998711886 2190 0
993609666 2189 0
993564892 2188 0
993337990 2187 0
990189463 2186 0
989695853 2185 0
989109013 2184 0
988821962 2183 0
988516017 2182 0
987849359 2181 0
999978170 2100 0
999695902 2099 0
999125452 2098 0
998647558 2097 0
998318778 2096 0
998294892 2095 0
997257845 2094 0
996955629 2093 0
995414877 2092 0
993821835 2091 0
993564892 2190 0
993337990 2189 0
989695853 2188 0
989109013 2187 0
988821962 2186 0
988516017 2185 0
987536948 2184 0
987163675 2183 0
986968956 2182 0
986827090 2181 0
999857288 2100 0
999616351 2099 0
998368834 2098 0
997873176 2097 0
997765653 2096 0
997408365 2095 0
997155472 2094 0
996624988 2093 0
996554897 2092 0
995752997 2091 0
994620752 2190 0
993501204 2189 0
992995909 2188 0
992694883 2187 0
991833398 2186 0
991623234 2185 0
991366167 2184 0
990890750 2183 0
990418342 2182 0
990115872 2181 0
999857288 2100 0
999616351 2099 0
998368834 2098 0
997873176 2097 0
997765653 2096 0
997408365 2095 0
997155472 2094 0
996624988 2093 0
996554897 2092 0
995752997 2091 0
994620752 2190 0
993544580 2189 0
993501204 2188 0
992995909 2187 0
992694883 2186 0
991833398 2185 0
991623234 2184 0
991366167 2183 0
990418342 2182 0
990115872 2181 0
999857288 2100 0
999616351 2099 0
998368834 2098 0
997873176 2097 0
997765653 2096 0
997408365 2095 0
997155472 2094 0
996624988 2093 0
996554897 2092 0
995752997 2091 0
994620752 2190 0
993501204 2189 0
992995909 2188 0
992694883 2187 0
991833398 2186 0
991623234 2185 0
991366167 2184 0
990418342 2183 0
990115872 2182 0
989916886 2181 0
999857288 2100 0
999616351 2099 0
998368834 2098 0
997873176 2097 0
997765653 2096 0
997408365 2095 0
997155472 2094 0
997131146 2093 0
996624988 2092 0
996554897 2091 0
999339046 2190 0
995752997 2189 0
994620752 2188 0
993501204 2187 0
992995909 2186 0
992694883 2185 0
991833398 2184 0
991668588 2183 0
991623234 2182 0
991366167 2181 0
999857288 2100 0
999616351 2099 0
998368834 2098 0
997873176 2097 0
997765653 2096 0
997408365 2095 0
997155472 2094 0
997040842 2093 0
996624988 2092 0
996554897 2091 0
995752997 2190 0
994620752 2189 0
993501204 2188 0
992995909 2187 0
992694883 2186 0
991833398 2185 0
991623234 2184 0
991366167 2183 0
990418342 2182 0
990115872 2181 0
998929008 2100 0
998892631 2099 0
998417491 2098 0
997943448 2097 0
997794088 2096 0
997737909 2095 0
997348902 2094 0
996520774 2093 0
995870736 2092 0
994365434 2091 0
993620204 2190 0
993540507 2189 0
992579113 2188 0
992538505 2187 0
992477623 2186 0
991842087 2185 0
991701814 2184 0
991586331 2183 0
991310511 2182 0
990808484 2181 0
998929008 2100 0
998892631 2099 0
998417491 2098 0
998290085 2097 0
997943448 2096 0
997794088 2095 0
997737909 2094 0
997348902 2093 0
996520774 2092 0
995870736 2091 0
994365434 2190 0
993620204 2189 0
993540507 2188 0
993425143 2187 0
992900513 2186 0
992579113 2185 0
992559230 2184 0
992538505 2183 0
992477623 2182 0
991842087 2181 0
998929008 2100 0
998892631 2099 0
998417491 2098 0
997943448 2097 0
997794088 2096 0
997737909 2095 0
997348902 2094 0
996520774 2093 0
995870736 2092 0
994365434 2091 0
999902949 2190 0
993620204 2189 0
993540507 2188 0
992579113 2187 0
992538505 2186 0
992477623 2185 0
991842087 2184 0
991701814 2183 0
991586331 2182 0
991310511 2181 0
998929008 2100 0
998892631 2099 0
998417491 2098 0
997943448 2097 0
997794088 2096 0
997737909 2095 0
997348902 2094 0
996520774 2093 0
995870736 2092 0
994365434 2091 0
994553424 2190 0
993620204 2189 0
993540507 2188 0
992579113 2187 0
992538505 2186 0
992477623 2185 0
991842087 2184 0
991701814 2183 0
991586331 2182 0
991310511 2181 0
998929008 2100 0
998892631 2099 0
998417491 2098 0
997943448 2097 0
997794088 2096 0
997737909 2095 0
997527769 2094 0
997348902 2093 0
996520774 2092 0
995870736 2091 0
998764387 2190 0
997519331 2189 0
996640160 2188 0
994365434 2187 0
993620204 2186 0
993540507 2185 0
992579113 2184 0
992538505 2183 0
992477623 2182 0
991842087 2181 0
Advanced test...998494804 100 0
998494804 200 0
998494804 300 0
998494804 400 0
999259797 500 0
999259797 600 0
999259797 700 0
999597640 800 0
999597640 900 0
999597640 1000 0
999597640 1100 0
999597640 1200 0
999597640 1300 0
999597640 1400 0
999597640 1500 0
999597640 1600 0
999979960 1700 0
999979960 1800 0
999979960 1900 0
999979960 2000 0
980013016 100 0
989330455 200 0
993250383 300 0
993250383 400 0
993250383 500 0
997353629 600 0
997353629 700 0
998371001 800 0
998371001 900 0
998371001 1000 0
998371001 1100 0
998371001 1200 0
998371001 1300 0
998371001 1400 0
998390895 1500 0
998390895 1600 0
998390895 1700 0
998390895 1800 0
998390895 1900 0
998390895 2000 0
Advanced copy&= test...998982356 2100 0
998758576 2099 0
997716203 2098 0
997526203 2097 0
997288253 2096 0
997156193 2095 0
996221304 2094 0
996050610 2093 0
995719600 2092 0
995018448 2091 0
999901128 2190 0
994781744 2189 0
994370972 2188 0
994274784 2187 0
993750945 2186 0
993691118 2185 0
993252810 2184 0
993066399 2183 0
992989829 2182 0
991827236 2181 0
999880213 2100 0
998982356 2099 0
998758576 2098 0
998102046 2097 0
997716203 2096 0
997288253 2095 0
997156193 2094 0
996221304 2093 0
996050610 2092 0
995719600 2091 0
997480983 2190 0
995018448 2189 0
994781744 2188 0
994370972 2187 0
994274784 2186 0
993750945 2185 0
993691118 2184 0
993252810 2183 0
993066399 2182 0
992989829 2181 0
999852383 2100 0
998982356 2099 0
998758576 2098 0
997975544 2097 0
997716203 2096 0
997288253 2095 0
997156193 2094 0
996221304 2093 0
996050610 2092 0
995719600 2091 0
998177521 2190 0
995018448 2189 0
994781744 2188 0
994703644 2187 0
994370972 2186 0
994274784 2185 0
993750945 2184 0
993691118 2183 0
993252810 2182 0
993066399 2181 0
998982356 2100 0
998758576 2099 0
997716203 2098 0
997288253 2097 0
997156193 2096 0
996221304 2095 0
996050610 2094 0
995719600 2093 0
995018448 2092 0
994781744 2091 0
999276597 2190 0
994370972 2189 0
994274784 2188 0
993750945 2187 0
993691118 2186 0
993252810 2185 0
993066399 2184 0
992989829 2183 0
991827236 2182 0
991056069 2181 0
998982356 2100 0
998758576 2099 0
997716203 2098 0
997288253 2097 0
997156193 2096 0
996221304 2095 0
996050610 2094 0
995719600 2093 0
995018448 2092 0
994781744 2091 0
994691086 2190 0
994370972 2189 0
994274784 2188 0
993750945 2187 0
993691118 2186 0
993252810 2185 0
993066399 2184 0
992989829 2183 0
991827236 2182 0
991056069 2181 0
999981689 2100 0
999926240 2099 0
999136949 2098 0
998310732 2097 0
998222616 2096 0
996784238 2095 0
996513735 2094 0
996324343 2093 0
996046886 2092 0
995959209 2091 0
999586063 2190 0
996721585 2189 0
995827780 2188 0
995800233 2187 0
995788874 2186 0
995611089 2185 0
994749983 2184 0
994724323 2183 0
993979643 2182 0
993882385 2181 0
999981689 2100 0
999926240 2099 0
999136949 2098 0
998310732 2097 0
998222616 2096 0
996784238 2095 0
996513735 2094 0
996498630 2093 0
996324343 2092 0
996046886 2091 0
995959209 2190 0
995827780 2189 0
995800233 2188 0
995788874 2187 0
994754883 2186 0
994749983 2185 0
994724323 2184 0
993979643 2183 0
993882385 2182 0
992805200 2181 0
999981689 2100 0
999926240 2099 0
999136949 2098 0
998310732 2097 0
998222616 2096 0
996784238 2095 0
996513735 2094 0
996478182 2093 0
996324343 2092 0
996046886 2091 0
995959209 2190 0
995827780 2189 0
995800233 2188 0
995788874 2187 0
994749983 2186 0
994724323 2185 0
993979643 2184 0
993882385 2183 0
992805200 2182 0
992747081 2181 0
999981689 2100 0
999926240 2099 0
999136949 2098 0
998310732 2097 0
998222616 2096 0
996784238 2095 0
996513735 2094 0
996324343 2093 0
996046886 2092 0
995959209 2091 0
995827780 2190 0
995800233 2189 0
995788874 2188 0
994749983 2187 0
994724323 2186 0
993979643 2185 0
993882385 2184 0
992805200 2183 0
992747081 2182 0
990854278 2181 0
999981689 2100 0
999926240 2099 0
999136949 2098 0
998310732 2097 0
998240485 2096 0
998222616 2095 0
996784238 2094 0
996513735 2093 0
996324343 2092 0
996046886 2091 0
995959209 2190 0
995827780 2189 0
995800233 2188 0
995788874 2187 0
994749983 2186 0
994724323 2185 0
993979643 2184 0
993882385 2183 0
992805200 2182 0
992747081 2181 0
Exception test...Accept

View File

@ -0,0 +1,213 @@
// provided by xzj
#include <iostream>
#include <queue>
#include <ctime>
#include <cstdio>
#include "priority_queue.hpp"
long long aa=13131,bb=5353,MOD=1e9+7,now=1;
int rand()
{
for(int i=1;i<3;i++)
now=(now * aa + bb) % MOD;
return now;
}
class T1//no_construct
{
public:
int data;
T1(int key):data(key){}
};
bool operator == (const T1 &a,const T1 &b)
{
return a.data == b.data;
}
std::ostream &operator <<(std::ostream &os, const T1 &a){
os<<a.data;
return os;
}
class T2//pointer + no_construct
{
public:
int *data;
T2(int key):data(new int(key)){}
T2(const T2 &other):data(new int(*(other.data))){}
T2&operator = (const T2 &other)
{
if(this == &other) return *this;
delete data;
data = new int(*(other.data));
return *this;
}
~T2(){delete data;}
};
bool operator == (const T2 &a,const T2 &b)
{
return *(a.data) == *(b.data);
}
std::ostream &operator <<(std::ostream &os, const T2 &a){
os<<*(a.data);
return os;
}
class T3
{
public:
int data;
T3():data(0){}
T3(int key):data(key){}
};
bool operator == (const T3 &a,const T3 &b)
{
return a.data == b.data;
}
std::ostream &operator <<(std::ostream &os, const T3 &a){
os<<a.data;
return os;
}
class T4//pointer
{
public:
int *data;
T4():data(new int(0)){}
T4(int key):data(new int(key)){}
T4(const T4 &other):data(new int(*(other.data))){}
T4&operator = (const T4 &other)
{
if(this == &other) return *this;
delete data;
data = new int(*(other.data));
}
~T4(){delete data;}
};
bool operator == (const T4 &a,const T4 &b)
{
return *(a.data) == *(b.data);
}
std::ostream &operator <<(std::ostream &os, const T4 &a){
os<<*(a.data);
return os;
}
struct cmp{
bool operator ()(const T1 &a,const T1 &b)const{return a.data < b.data;}
bool operator ()(const T2 &a,const T2 &b)const{return *(a.data) < *(b.data);}
bool operator ()(const T3 &a,const T3 &b)const{return a.data < b.data;}
bool operator ()(const T4 &a,const T4 &b)const{return *(a.data) < *(b.data);}
bool operator ()(const int &a,const int &b)const{return a < b;}
};
template<class T>
void test()
{
sjtu::priority_queue<T,cmp> q;
int test_num=2000;
for(int i=1;i<=test_num;i++)
{
q.push(T(rand()));
if(i % 100==0)
{
std::cout<<q.top()<<' '<<q.size()<<' '<<q.empty()<<std::endl;
}
if(i % 100 > 900)
q.pop();
}
}
template<class T>
void copy_test()
{
sjtu::priority_queue<T,cmp> q;
int num=2000;
for(int i=1;i<=num;i++)
q.push(T(rand()));
for(int j=1;j<=5;j++)
{
sjtu::priority_queue<T,cmp> t(q);
for(int i=1;i<=100;i++)
t.push(T(rand()));
for(int k=1;k<=10;k++)
{
std::cout<<t.top()<<' '<<t.size()<<' '<<t.empty()<<std::endl;
t.pop();
}
sjtu::priority_queue<T,cmp> p;
p=t;
p=p=p=p;
for(int i=1;i<=100;i++)
p.push(T(rand()));
for(int k=1;k<=10;k++)
{
std::cout<<p.top()<<' '<<p.size()<<' '<<p.empty()<<std::endl;
p.pop();
}
}
}
void normal_test()
{
puts("Normal test...");
test<int>();
test<T3>();
test<T4>();
}
void advanced_test()
{
printf("Advanced test...");
test<T1>();
test<T2>();
}
void normal_copy_test()
{
printf("Normal copy&= test...");
copy_test<int>();
copy_test<T3>();
copy_test<T4>();
}
void advanced_copy_test()
{
printf("Advanced copy&= test...");
copy_test<T1>();
copy_test<T2>();
}
void exception_test()
{
bool flag = 0;
printf("Exception test...");
sjtu::priority_queue<int,cmp> q;
for(int i=1;i<=100;i++)
q.push(rand());
for(int i=1;i<=100;i++)
q.pop();
try{
q.pop();
}
catch(sjtu::container_is_empty) {flag = 1;}
catch(...){flag = 0;}
if(!flag)
{
puts("Wrong Answer(pop)");
return;
}
try{
int tmp(q.top());
}
catch(sjtu::container_is_empty) {flag = 1;}
catch(...){flag = 0;}
if(!flag)
{
puts("Wrong Answer(top)");
return;
}
puts("Accept");
}
int main(int argc, char *const argv[])
{
//freopen("testans-priority_queue-advance","w",stdout);
puts("Test Start");
normal_test();
normal_copy_test();
advanced_test();
advanced_copy_test();
exception_test();
return 0;
}