ZJU 2671 Cryptography
Cryptography
This problem will be judged on ZJU. Original ID: 2671
64-bit integer IO format: %lld Java class name: Main
Young cryptoanalyst Georgie is planning to break the new cipher invented by his friend Andie. To do this, he must make some linear transformations over the ring Zr = Z/rZ.
Each linear transformation is defined by 2×2 matrix. Georgie has a sequence of matrices A1 , A2 ,..., An . As a step of his algorithm he must take some segment Ai , Ai+1 , ..., Aj of the sequence and multiply some vector by a product Pi,j=Ai × Ai+1 × ... × Aj of the segment. He must do it for m various segments.
Help Georgie to determine the products he needs.
Input
There are several test cases in the input. The first line of each case contains r (1 <= r <= 10,000), n (1 <= n <= 30,000) and m (1 <= m <= 30,000). Next n blocks of two lines, containing two integer numbers ranging from 0 to r - 1 each, describe matrices. Blocks are separated with blank lines. They are followed by m pairs of integer numbers ranging from1 to n each that describe segments, products for which are to be calculated.
There is an empty line between cases.
Output
Print m blocks containing two lines each. Each line should contain two integer numbers ranging from 0 to r - 1 and define the corresponding product matrix.
There should be an empty line between cases.
Separate blocks with an empty line.
Sample
Input
3 4 4
0 1
0 0 2 1
1 2 0 0
0 2 1 0
0 2 1 4
2 3
1 3
2 2 Output
0 2
0 0 0 2
0 1 0 1
0 0 2 1
1 2
Source
解题:坑爹的线段树
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
struct Matrix {
int m[][];
};
struct node {
int lt,rt;
Matrix matrix;
};
node tree[maxn<<];
int r,n,m;
Matrix Multiplication(const Matrix &a,const Matrix &b) {
Matrix c;
c.m[][] = (a.m[][]*b.m[][] + a.m[][]*b.m[][])%r;
c.m[][] = (a.m[][]*b.m[][] + a.m[][]*b.m[][])%r;
c.m[][] = (a.m[][]*b.m[][] + a.m[][]*b.m[][])%r;
c.m[][] = (a.m[][]*b.m[][] + a.m[][]*b.m[][])%r;
return c;
}
void read(Matrix &c) {
for(int i = ; i < ; ++i)
for(int j = ; j < ; ++j)
scanf("%d",&c.m[i][j]);
}
void build(int lt,int rt,int v) {
tree[v].lt = lt;
tree[v].rt = rt;
if(lt == rt) {
if(lt <= n) read(tree[v].matrix);
else {
tree[v].matrix.m[][] = ;
tree[v].matrix.m[][] = ;
tree[v].matrix.m[][] = ;
tree[v].matrix.m[][] = ;
}
return;
}
int mid = (lt+rt)>>;
build(lt,mid,v<<);
build(mid+,rt,v<<|);
tree[v].matrix = Multiplication(tree[v<<].matrix,tree[v<<|].matrix);
}
Matrix query(int lt,int rt,int v){
if(tree[v].lt == lt && tree[v].rt == rt) return tree[v].matrix;
int mid = (tree[v].lt + tree[v].rt)>>;
if(rt <= mid) return query(lt,rt,v<<);
else if(lt > mid) return query(lt,rt,v<<|);
else return Multiplication(query(lt,mid,v<<),query(mid+,rt,v<<|));
}
int main() {
bool cao = false;
while(~scanf("%d %d %d",&r,&n,&m)){
int k = log2(n) + ;
k = <<k;
build(,k,);
if(cao) puts("");
cao = true;
bool flag = false;
while(m--){
int s,t;
if(flag) puts("");
flag = true;
scanf("%d %d",&s,&t);
Matrix ans = query(s,t,);
for(int i = ; i < ; ++i)
printf("%d %d\n",ans.m[i][],ans.m[i][]);
}
}
return ;
}
ZJU 2671 Cryptography的更多相关文章
- ZOJ 2671 Cryptography 矩阵乘法+线段树
B - Cryptography Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Subm ...
- ZOJ - 2671 Cryptography(线段树+求区间矩阵乘积)
题意:已知n个矩阵(下标从1开始),求下标x~y区间矩阵的乘积.最多m次询问,n ( 1 <= n <= 30,000) and m ( 1 <= m <= 30,000). ...
- .Net使用system.Security.Cryptography.RNGCryptoServiceProvider类与System.Random类生成随机数
.Net中我们通常使用Random类生成随机数,在一些场景下,我却发现Random生成的随机数并不可靠,在下面的例子中我们通过循环随机生成10个随机数: ; i < ; i++) { Rando ...
- ECC-Elliptic Curves Cryptography,椭圆曲线密码编码学
ECC ECC-Elliptic Curves Cryptography,椭圆曲线密码编码学,是目前已知的公钥体制中,对每比特所提供加密强度最高的一种体制.在软件注册保护方面起到很大的作用,一般的序列 ...
- "System.Security.Cryptography.CryptographicException: 拒绝访问" 问题的解决方法
.net web程序使用rsa算法进行加解密时,程序报告“System.Security.Cryptography.CryptographicException: 拒绝访问”错.按网上搜的解决方法做了 ...
- System.Security.Cryptography.CryptographicException: 指定了无效的提供程序类型
这两天在调用银联在线的支付接口,把银联提供的demo代码copy过来放到自己网站上,生成通过了,但是运行的时候就报错了: 指定了无效的提供程序类型. 说明: 执行当前 Web 请求期间,出现未经处理的 ...
- Raspberry Pi 3 FAQ --- connect automatically to 'mirrors.zju.edu.cn' when downloading and how to accelerate download
modify the software source: The software source is a place where several free application for linux ...
- [POJ2109]Power of Cryptography
[POJ2109]Power of Cryptography 试题描述 Current work in cryptography involves (among other things) large ...
- ACM: Gym 100935B Weird Cryptography - 简单的字符串处理
Weird Cryptography Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
随机推荐
- CodeForcesGym 100676G Training Camp
G. Training Camp Time Limit: 1000ms Memory Limit: 262144KB This problem will be judged on CodeForces ...
- 关于参数net_buffer_length How MySQL Uses Memory
http://dev.mysql.com/doc/refman/5.6/en/memory-use.html The following list indicates some of the ways ...
- nodejs-安装及卸载
linux下安装node 1.编译的方式安装 1 2 3 4 5 6 7 wget http://nodejs.org/dist/node-latest.tar.gz tar zxvf node-l ...
- 推荐几款VisualStudio的插件
继前几天推荐了一款转换vs插件的插件后,借着安装VS2013之际,把我比较喜欢的几个插件继续推荐一下. C# Outline 2013 2013 C#的代码折叠最小只能到函数级,不像C++那样可以折叠 ...
- 交叉编译faac共享库
作者:咕唧咕唧liukun321 来自:http://blog.csdn.net/liukun321 Advanced Audio Coding.一种专为声音数据设计的文件压缩格式,与Mp3不同,它採 ...
- Chrome插件开发新手教程
近期在用百词斩这个站点来学单词,感觉非常不错,就是在回想单词列表的时候仅仅有单词和意思.却没有读音.感觉非常不方便,思来思去,想到了Chrome插件能够胜任这个工作.于是小小的研究了一下. Chrom ...
- Java-API-POI:POI百科
ylbtech-Java-API:POI百科 Apache POI是Apache软件基金会的开放源码函式库,POI提供API给Java程序对Microsoft Office格式档案读和写的功能. 1. ...
- springmvc-mvc:resource标签使用
转自:http://www.cnblogs.com/gzulmc/p/6746174.html <!-- 配置静态资源 --><mvc:resources location=&quo ...
- HD-ACM算法专攻系列(16)——考试排名
问题描述: 源码: 主要要注意输出格式. #include"iostream" #include"iomanip" #include"algorith ...
- usaco 最少找零
Description 约翰在镇上买了 T 元钱的东西,正在研究如何付钱.假设有 N 种钞票,第 i 种钞票的面值为 Vi,约翰身上带着这样的钞票 Ci 张.商店老板罗伯是个土豪,所有种类的钞票都有无 ...