QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#10742 | #559. 原力 | Pdw2007 | 100 ✓ | 378ms | 89620kb | C++98 | 1.4kb | 2021-06-18 15:07:53 | 2023-08-25 01:10:25 |
Judging History
answer
#include<map>
#include<cmath>
#include<cstdio>
#define rep(i,l,r) for (int i=l; i<=r; i++)
typedef long long ll;
using namespace std;
const int N=50100,mod=1000000007;
struct data{
int x,y,z; data() {}
data(int a,int b,int c) {x=a,y=b,z=c;}
bool operator<(const data &a)const {return x == a.x ? y == a.y ? z < a.z : y < a.y : x < a.x;}
};
map<data,ll> mp;
int n,m,si,x,y,z,t,head[N],to[N << 2],val[N << 2],opt[N << 2],next[N << 2],cnt,d[N],id[350],tot;
char str[5];
void add(int x,int y,int v,int c){ to[++cnt]=y,val[cnt]=v,opt[cnt]=c,next[cnt]=head[x],head[x]=cnt; }
int main(){
ll ans=0; scanf("%d%d",&n,&m),si=(int)sqrt(m);
rep(i,1,m){
scanf("%d%d%d%s",&x,&y,&z,str);
t=(str[0] == 'R' ? 1 : str[0] == 'G' ? 2 : 3);
add(x,y,z,t),add(y,x,z,t),d[x] ++,d[y] ++ ;
(mp[data(x,y,t)] += z) %= mod,(mp[data(y,x,t)] += z) %= mod;
}
rep(i,1,n) if(d[i] >= si) id[++tot]=i;
rep(i,1,tot) rep(j,1,tot) rep(k,1,tot)
ans=(ans+mp[data(id[i],id[j],1)]*mp[data(id[i],id[k],2)]%mod*mp[data(id[j],id[k],3)])%mod;
rep(i,1,n) if(d[i] < si)
for(int j=head[i] ; j ; j=next[j])
if(d[to[j]] >= si || to[j] > i)
for(int k=next[j]; k; k=next[k])
if(opt[k]!=opt[j] && (d[to[k]]>=si || to[k]>i))
ans=(ans+mp[data(to[j],to[k],6-opt[j]-opt[k])]*val[j]%mod*val[k])%mod;
printf("%lld\n",ans);
return 0;
}
详细
Test #1:
score: 10
Accepted
time: 3ms
memory: 4276kb
input:
85 1024 26 70 3 B 75 47 7 G 23 81 7 R 70 68 7 B 51 26 9 R 41 72 8 R 31 46 2 G 82 7 5 G 6 15 2 B 50 44 4 R 41 17 3 G 58 41 8 B 82 22 4 R 9 39 8 B 54 61 7 R 23 29 6 G 68 52 5 R 28 57 7 G 36 39 4 G 74 83 2 B 58 14 4 G 30 39 1 R 38 76 5 G 19 8 3 R 36 48 5 B 71 76 4 B 33 65 8 R 53 81 10 B 28 72 8 G 21 52...
output:
90693
result:
ok 1 number(s): "90693"
Test #2:
score: 10
Accepted
time: 187ms
memory: 6072kb
input:
95 16384 73 45 5 B 57 95 31 G 52 94 52 R 54 45 98 G 81 40 96 R 37 1 15 R 81 91 13 B 66 4 81 B 89 93 43 R 40 23 27 G 30 68 24 G 85 32 98 G 82 86 21 B 24 18 39 R 60 39 29 R 62 74 32 B 77 15 59 R 77 13 59 G 10 53 98 R 24 32 99 G 80 70 52 R 77 49 29 G 19 76 88 G 25 2 55 B 61 92 18 B 44 50 53 R 70 75 1 B...
output:
34773089
result:
ok 1 number(s): "34773089"
Test #3:
score: 10
Accepted
time: 268ms
memory: 8904kb
input:
99 100000 14 25 53839 G 6 22 555681 G 14 58 127533 B 93 30 685857 G 86 68 720946 G 14 59 657691 B 40 57 159703 R 59 83 309777 G 7 99 151251 B 57 77 769566 G 11 4 406698 R 14 60 739074 G 18 51 934158 R 39 14 237859 B 59 70 810047 G 14 35 733152 R 38 19 549269 R 37 79 413532 B 87 7 30363 B 83 7 795910...
output:
300572702
result:
ok 1 number(s): "300572702"
Test #4:
score: 10
Accepted
time: 91ms
memory: 17992kb
input:
4999 50000 3515 625 2 G 1458 3602 1 G 2400 3744 8 R 625 4677 10 G 3602 4385 5 B 4716 2535 7 B 1057 1829 7 R 3691 3073 7 R 1583 1852 7 G 4427 153 10 G 4774 1298 6 R 836 2610 3 G 2022 2207 4 G 3481 4450 6 R 1477 3602 3 G 2399 4851 7 G 3073 3532 9 G 795 2764 9 B 3053 2908 6 G 3979 3239 8 R 4877 863 4 G...
output:
7585569
result:
ok 1 number(s): "7585569"
Test #5:
score: 10
Accepted
time: 68ms
memory: 17632kb
input:
9999 50000 8342 1822 1 R 2454 7542 91 R 4747 6417 54 G 6114 790 56 G 2423 3828 71 G 9534 6417 66 G 6907 9508 93 B 7593 2449 100 B 7037 6417 73 B 8149 1505 10 G 728 5819 91 R 6417 5132 58 B 8046 5108 25 G 9320 4005 13 G 2577 6417 92 G 1154 5596 45 B 3115 8046 61 G 6417 3191 14 B 6417 2556 92 R 6417 6...
output:
305858005
result:
ok 1 number(s): "305858005"
Test #6:
score: 10
Accepted
time: 70ms
memory: 20012kb
input:
39999 50000 711 20333 781142 R 23113 14256 146398 G 36974 20333 525277 R 36111 33004 752115 B 8782 20662 280729 G 25188 9984 379947 B 20333 35283 24241 R 29867 20333 316858 G 17063 20333 204821 B 32466 11296 757600 G 18780 39492 833820 R 20333 32132 963038 G 6250 38375 764880 R 11296 35435 774020 G ...
output:
910002950
result:
ok 1 number(s): "910002950"
Test #7:
score: 10
Accepted
time: 378ms
memory: 89620kb
input:
20000 100000 16355 4798 940 G 13008 13907 349 G 4798 17727 621 R 13008 5194 836 G 13008 18776 111 G 4739 13008 599 B 4798 7237 850 G 13008 6737 228 G 13008 14079 199 B 2532 208 645 B 4798 15196 267 B 8734 18039 668 G 17823 17093 141 G 16325 15294 171 R 13008 15936 950 G 13806 13008 855 R 4104 11188 ...
output:
74652463
result:
ok 1 number(s): "74652463"
Test #8:
score: 10
Accepted
time: 174ms
memory: 30428kb
input:
30000 100000 3757 12254 1505 B 7935 28786 71 B 15119 2468 960 G 12418 15335 468 G 3378 220 534 B 14160 5855 494 B 20502 10202 284 G 1655 11330 36 R 11744 14165 388 R 10444 6281 1463 R 18863 14050 847 G 5311 511 1317 B 6734 75 1224 B 21061 7652 1846 R 22703 14160 1073 B 11890 6592 1002 B 25235 21600 ...
output:
600759360
result:
ok 1 number(s): "600759360"
Test #9:
score: 10
Accepted
time: 127ms
memory: 22180kb
input:
40000 100000 677 7952 47133 B 26245 25217 20330 B 27073 5097 79391 B 24358 23616 90279 G 32570 33531 95478 B 11357 21106 34680 R 11974 27868 17701 R 12937 16890 53472 G 6967 7513 35198 G 27987 11357 58966 B 35641 7203 95467 G 11357 19348 86505 R 27597 34548 53863 R 31334 11357 28148 G 11303 23560 83...
output:
773736079
result:
ok 1 number(s): "773736079"
Test #10:
score: 10
Accepted
time: 161ms
memory: 25444kb
input:
50000 100000 6823 20867 761119 R 15633 41381 594787 G 15521 17722 827117 B 22016 5255 111472 G 33162 21404 102291 G 20232 39357 226738 G 31698 23330 668274 R 41381 11664 404107 B 4517 4277 115972 B 185 719 279579 G 16463 47896 310079 B 3434 32893 16111 B 44769 6560 943760 G 44874 41381 183542 B 1996...
output:
674393235
result:
ok 1 number(s): "674393235"